JavaScript Day 9 — Mastering JavaScript Basics: A Comprehensive Guide for Interview Preparation
100 Days of JavaScript Interview Prep: A Beginner’s Journey
Welcome to Day 9–100 Days of JavaScript Interview Prep: A Beginner’s Journey


Join us as we document a 100-day adventure filled with learning, practice, and growth.
DAY 9 (March 31, 2024) —Primitive and Non-primitive Data Types Interview Questions
Question 1 : What are primitive data types in JavaScript?
Answer:
A primitive (primitive value, primitive data type) is data that is not an object and has no methods or properties.
There are 7 primitive data types
All primitives are immutable; that is, they cannot be altered
Number: let num = 10;
String: let str = "Hello";
Boolean: let bool = true;
Null: let nullValue = null;
Undefined: let undefinedValue;
Symbol: let sym = Symbol("foo");
BigInt
Question 2: Differentiate between primitive and non-primitive data types in JavaScript, with examples?
Answer
Primitive data types
- Primitive data types are immutable and stored directly in the variable, while non-primitive data types are mutable and stored by reference.
- Primitive values are stored directly in the variable’s memory location.
- Primitive Data Types: Passed by value. When passing a primitive value to a function, a copy of the value is passed.
- Primitive Data Types: Typically smaller and fixed.
Example of primitive type:
Primitive Data Types: Number, String, Boolean, Null, Undefined, Symbol.
let num = 10;
let str = "Hello world";Non-primitive data types
- Non-primitive data types are mutable.
- They can be modified after creation.
- Non-primitive values are stored by reference.
- Variables hold references (memory addresses) to the actual object stored in the heap
- Non-Primitive Data Types: Object (including arrays, functions, and other objects).
- Non-Primitive Data Types: Passed by reference. When passing a non-primitive value to a function, the reference to the original value is passed.
- Non-Primitive Data Types: Can vary in size based on the contents of the object and are dynamically resizable.
let employee= { name: "tommy", age: 23 };
let myNumbers= [1, 2, 3,4,5];Kind is cool !!! Share knowledge to gain knowledge !!!! Be kind and treat people with respect !!
If you find my videos helpful, then please subscribe, Claps and follow to support
Cheers
Kirti Kaushal







