Practice questions: language foundations
Language foundations18 min readLesson 4 of 4
Attempt each question before reading the answer. The examples use the same console-based scripts as the module, so every answer can be checked by running the snippet in Node or the browser console.
4.1 Q1 What is the difference between let and const?
Answer (English): let creates a binding that can be reassigned, while const creates a binding that cannot be pointed at a new value after initialisation. Both are block scoped and both create a temporary dead zone before their declaration. A const object or array can still be mutated, because the binding is fixed but the value is not frozen.
Hinglish: let ka value baad mein badal sakta hai, const ko dobara assign nahi kar sakte. Dono block scope follow karte hain aur declaration se pehle use karne par ReferenceError aata hai. const object ya array ke andar ke values phir bhi badal sakte hain, kyunki const sirf naam ko fix karta hai.
4.2 Q2 What does typeof null return, and why?
Answer (English): It returns "object". This is a historical bug in the first JavaScript implementation that was preserved for backward compatibility. Test for null with value === null instead of relying on typeof, and remember that arrays also report "object".
Hinglish: typeof null "object" deta hai. Yeh JavaScript ke shuruaati implementation ki purani galti hai jo compatibility ke liye chhod di gayi. Null check ke liye value === null use karo; arrays ka typeof bhi object hi aata hai.
4.3 Q3 What is the difference between == and ===?
Answer (English): == converts operands to a common type before comparing, so 0 == "0" is true. === compares both type and value, so 0 === "0" is false. Use strict equality for predictable comparisons, and reserve loose equality for deliberate null-or-undefined checks.
Hinglish: == pehle type convert karke compare karta hai, isliye 0 == "0" true hota hai. === type aur value dono check karta hai, isliye 0 === "0" false hota hai. Aam comparisons ke liye === use karo.
4.4 Q4 What does "5" + 2 evaluate to, and why?
Answer (English): It evaluates to the string "52". The + operator sees a string operand and chooses concatenation, so the number 2 is converted to text. This is different from "5" - 2, where subtraction converts both sides to numbers and returns 3.
Hinglish: "5" + 2 string "52" deta hai, kyunki + ko string mili to woh concatenation karta hai aur number ko text bana deta hai. "5" - 2 mein subtraction dono ko number banata hai, isliye 3 aata hai.
4.5 Q5 Explain block scope in JavaScript with the level example.
Answer (English): A name declared with let or const exists only inside the nearest pair of braces. In the example, the inner level shadows the outer one inside the if block, so the first log prints inner. After the block ends, the outer binding is visible again and the second log prints outer.
Hinglish: let ya const se banaya naam sirf nearest braces ke andar rehta hai. Example mein if block ke andar wala level bahar wale ko shadow karta hai, isliye pehla log inner deta hai. Block khatam hone par bahar wala naam phir dikhta hai aur dusra log outer deta hai.
4.6 Q6 What is the temporary dead zone?
Answer (English): It is the period between the start of a block and the declaration of a let or const name in that block. Reading the name during that period throws a ReferenceError instead of returning undefined. The rule catches use-before-declaration mistakes early.
Hinglish: Temporary dead zone block ke shuru se lekar let ya const declaration tak ka time hota hai. Us dauran naam padhne par undefined nahi, ReferenceError aata hai. Yeh rule declaration se pehle use karne ki galti jaldi pakad leta hai.
4.7 Q7 How does var scope differ from let?
Answer (English): A var declaration ignores blocks and belongs to the nearest function, so it can leak out of an if or for block. let and const are block scoped. Modern code uses let and const because their scope matches the braces a reader sees.
Hinglish: var block ko ignore karke nearest function ka scope leta hai, isliye if ya for block se bahar bhi dikh sakta hai. let aur const block scope follow karte hain. Isliye aaj kal modern code mein let aur const use karte hain.
4.8 Q8 Why is 0.1 + 0.2 not equal to 0.3?
Answer (English): JavaScript stores numbers as 64-bit floating point values, and 0.1 and 0.2 cannot be represented exactly in binary. Their stored values add to 0.30000000000000004. For money, store paise or cents as integers or round both sides to the same precision before comparing.
Hinglish: JavaScript numbers 64-bit floating point hoti hain, aur 0.1 aur 0.2 binary mein exact store nahi hote. Unka sum 0.30000000000000004 aata hai. Paisa handle karna ho to paise ko integer mein rakho ya compare karne se pehle dono ko same precision par round karo.
4.9 Q9 What is the difference between null and undefined?
Answer (English): undefined means a value was not provided: an unassigned variable, a missing property, or a function without a return. null is a deliberate empty value set by the programmer. They are loosely equal but strictly unequal, and JSON supports null but not undefined.
Hinglish: undefined ka matlab value di hi nahi gayi, jaise unassigned variable ya missing property. null programmer ne jaan-boojh kar khaali value set ki hai. Dono == se equal hote hain par === se nahi, aur JSON mein null hota hai, undefined nahi.
4.10 Q10 How do &&, || and ?? differ?
Answer (English): && returns its first falsy operand or its last truthy operand. || returns its first truthy operand or its last falsy operand. ?? returns its right side only when the left is null or undefined, so it keeps 0, false and the empty string as real values.
Hinglish: && pehla falsy ya aakhri truthy operand deta hai. || pehla truthy ya aakhri falsy operand deta hai. ?? tab hi right side deta hai jab left null ya undefined ho, isliye 0, false aur khaali string ko real value maanta hai.
const score = 72;
const grade = score >= 60 ? "pass" : "fail";
const values = [42, "text", null];
console.log(`${grade}: ${score}`);
console.log(typeof null);
console.log(values.length);Output
pass: 72 object 3
The five-question quiz for this module is stored separately. Take it without scrolling back to these answers, then check the questions you missed against the notes. If two options look close, run the code and compare the printed value.
