📘 JavaScript Variables for Strings – Full Chapter Notes
🔷 What is a Variable?
• Variable ek container hota hai jisme hum data store karte hain.
• JavaScript mein variable banane ke liye let , const , ya var use hota hai.
🔷 What is a String?
• String means text.
• Quotes mein likha gaya data string hota hai:
let name = "Ali";
🔷 Syntax:
let name = "Ali";
const city = 'Lahore';
var greeting = `Hello`; // template string
🔷 Ways to Declare String Variables
1. let – changeable later
2. const – fixed (constant)
3. var – old way (avoid it in modern JS)
🟨 Section A: MCQs (with Answers)
1. Which keyword is recommended for changeable strings?
2. A. const
3. B. var
4. C. let ✅
5. How do you define a string?
1
6. A. let x = Hello;
7. B. let x = 'Hello'; ✅
8. C. let x = Hello';
9. Template literals use which quotes?
10. A. ""
11. B. ''
12. C. `` ✅
13. What is the result of:
let a = "5" + 5;
alert(a);
• A. 10
• B. 55 ✅
• C. Error
• What will typeof "Hello" return?
• A. string ✅
• B. text
• C. object
🟨 Section B: Short/Theoretical Questions
1. What is a string variable?
2. A variable that stores text in quotes.
3. Can we use numbers in string variables?
4. Yes, as characters: "123" is string, not number.
5. Difference between string and number?
6. "5" is text, 5 is number.
2
7. What is string concatenation?
8. Joining two strings:
let name = "Ali";
let msg = "Hello " + name;
9. What is template literal?
10. String inside backticks (``) with variables:
let msg = `Hello ${name}`;
🟨 Section C: Interview / Exam Questions
1. Real-life use of string variables?
2. To store user name, city, greetings, messages.
3. Difference: let vs const for strings?
4. let allows changes, const doesn't.
5. Can we store empty string?
6. Yes: let msg = "";
7. What happens if we don't use quotes?
8. JavaScript throws an error.
9. Can string hold numbers and text?
10. Yes: let info = "User123";
🧪 Section D: Code Output (Explain Each)
1. let name = "Ali"; alert(name); → "Ali"
2. alert("5" + 5); → "55"
3. alert(typeof "Hello"); → "string"
3
4. let x = 'Hi'; x = 'Bye'; alert(x); → "Bye"
5. const msg = 'Hi'; msg = 'Hello'; → ❌ Error (const can't be changed)
✅ Section E: True / False
Statement Answer
Strings are stored in quotes ✅ True
You can change const variable later ❌ False
Template strings use backticks ✅ True
'5' + 5 = 10 ❌ False
"Hello" is a string ✅ True
🔍 Section F: Tricky + Important Points
1. '5' + 5 = "55" → String + number = string
2. typeof("5") → "string"
3. Empty string is still valid: ""
4. "Ali" + 10 + 5 → "Ali105"
5. 10 + 5 + "Ali" → "15Ali"
6. alert("Hi" + true) → "Hitrue"
7. alert("Hi" + null) → "Hinull"
8. alert("Hello" + undefined) → "Helloundefined"
9. alert('5' * 2) → 10 (converted to number)
10. alert("abc" * 3) → NaN
📌 Summary:
• Strings = text inside quotes
•
let/const/var se variables bante hain
• operator se strings join hoti hain
• Template literals = backtick + \${}
• alert, [Link] se string print kar sakte ho
• JavaScript strict hai quotes ke bina error aata hai