🔥 Perfect — this is where learning becomes real fun + real skill.
Let’s lock in 🧠 Practice Set: JavaScript Primitives — all short, interactive-style challenges designed to build deep understanding of how each primitive behaves.
You can run these directly:
- In your browser console (F12 → Console), or
- In VS Code + Node.js (
node filename.js)
🧩 JavaScript Primitives – Practice Challenge Set
🧮 1️⃣ Numbers and Type Conversion
// Q1: Predict the output and then run it
console.log(5 + "5");
console.log("5" - 2);
console.log("10" * "2");
console.log("10" / "2");
console.log("10" / "A");
console.log(typeof NaN);
💬 Think:
Why is "5" + 5 → "55" but "5" - 2" → 3?
🔤 2️⃣ Strings Are Immutable
let word = "Hello";
word[0] = "Y";
console.log(word); // Still "Hello" ❌
word = "Yellow"; // ✅ New assignment
console.log(word);
💬 Task:
Try converting "hello world" → "Hello World" using string methods only.
🧠 Hint:
Use .split(), .map(), .toUpperCase(), .join().
🟢 3️⃣ Booleans and Truthy/Falsy Values
console.log(Boolean(0));
console.log(Boolean(" "));
console.log(Boolean(null));
console.log(Boolean([]));
console.log(Boolean({}));
💬 Task:
Write a function that prints "truthy" or "falsy" based on user input.
function checkTruthy(value) {
if (value) console.log("truthy");
else console.log("falsy");
}
checkTruthy(""); // falsy
checkTruthy("Rajeev"); // truthy
🚫 4️⃣ Undefined vs Null
let a;
let b = null;
console.log(a === b); // ?
console.log(typeof a); // ?
console.log(typeof b); // ?
💬 Task:
Explain difference in comments:
undefinedmeans…nullmeans…
🧱 5️⃣ Symbol Uniqueness
const s1 = Symbol("user");
const s2 = Symbol("user");
console.log(s1 === s2); // false
💬 Task:
Create an object using a Symbol as a hidden key:
const ID = Symbol("id");
let user = { name: "Rajeev", [ID]: 123 };
console.log(user[ID]); // ?
console.log(user.ID); // ?
Explain why user.ID doesn’t work.
🔢 6️⃣ BigInt Playground
let big = 9999999999999999999999n;
console.log(big + 10n);
// Uncomment below line and see the error
// console.log(big + 10);
💬 Task:
Why can’t you mix Number and BigInt directly?
How would you convert safely?
✅ Hint:
Number(big) + 10
🧩 7️⃣ Type Detector (Mini Project)
Let’s combine everything.
function detectType(value) {
console.log(`Value: ${value}, Type: ${typeof value}`);
}
detectType(42);
detectType("Hello");
detectType(true);
detectType(undefined);
detectType(null);
detectType(Symbol("x"));
detectType(10n);
💬 Bonus:
Why does typeof null return "object" even though null is a primitive?
(Hint: JS legacy bug from 1995)
🧠 8️⃣ Challenge – Type Conversion Mind Benders
Predict each output first, then run to verify:
console.log("5" + 5);
console.log("5" - 5);
console.log(true + true);
console.log(false + 10);
console.log("" + null);
console.log("5" + undefined);
💬 Explain each in terms of string concatenation vs numeric coercion.
🏆 Bonus: Create Your Own Type Tester (Browser Version)
Paste this into your browser console:
let value = prompt("Enter something:");
try {
let evaluated = eval(value);
alert(`Value: ${evaluated}, Type: ${typeof evaluated}`);
} catch {
alert(`Value: ${value}, Type: ${typeof value}`);
}
✅ Try with:
5
"hello"
true
null
undefined
123n
Symbol("a") ❌ (use console for symbols)
💡 Summary Skills You’ll Gain
✅ Understand each primitive type clearly
✅ Know how JS stores values (stack vs heap)
✅ Distinguish null vs undefined
✅ Use Symbol and BigInt properly
✅ Predict tricky coercion behaviors confidently
🔥 Excellent — this is exactly the right mindset for real-world mastery.
Here’s your “JavaScript Data Types & Memory Quiz – 10 Tricky Interview Questions” 🧠💥
Each question is MCQ-style, with explanations below (but try to answer first — no peeking 😉).
🧩 Chapter 1: JavaScript Primitives vs Non-Primitives — Interview Quiz
🧠 Q1. What will be the output?
let a = 10;
let b = a;
b = 20;
console.log(a);
A) 10
B) 20
C) ReferenceError
D) undefined
🧠 Q2. What’s the result of typeof null?
A) "null"
B) "undefined"
C) "object"
D) "NullType"
🧠 Q3. What is printed?
const obj1 = { name: "Rajeev" };
const obj2 = obj1;
obj2.name = "Priya";
console.log(obj1.name);
A) "Rajeev"
B) "Priya"
C) Error
D) undefined
🧠 Q4. Which of the following is NOT a primitive type?
A) Number
B) String
C) Object
D) Symbol
🧠 Q5. What is the result?
console.log(Symbol("id") === Symbol("id"));
A) true
B) false
C) undefined
D) Error
🧠 Q6. What is the output?
let arr1 = [1, 2, 3];
let arr2 = arr1;
arr2.push(4);
console.log(arr1);
A) [1, 2, 3]
B) [1, 2, 3, 4]
C) Error
D) undefined
🧠 Q7. What’s the result?
console.log(typeof NaN);
A) "number"
B) "NaN"
C) "undefined"
D) "object"
🧠 Q8. What’s true about BigInt in JavaScript?
A) It’s used for small numbers
B) You can mix it with normal numbers directly
C) It represents integers beyond 2⁵³–1
D) It’s deprecated
🧠 Q9. What happens here?
const user = { name: "Rajeev" };
user = { name: "Priya" };
console.log(user);
A) { name: "Priya" }
B) { name: "Rajeev" }
C) TypeError
D) undefined
🧠 Q10. Which statement is true?
A) Primitive values are stored in heap memory.
B) Objects are copied by value.
C) undefined and null are exactly the same.
D) Strings are immutable in JavaScript.
🏁 💥 Your Scorecard
✅ 8–10 → You’re at interview level — ready for tricky questions.
🟡 5–7 → Good foundation — revisit Symbol, reference types, and coercion.
🔴 0–4 → Redo Chapter 1 exercises — they’ll make everything click.