JavaScript uses variables as named containers to store data values, declared using keywords such as var, let, and const. The language features seven primitive data types String, Number, BigInt, Boolean, Undefined, Null, and Symbol alongside non-primitive reference types like Object, Array, and Function. Variable scoping changed significantly in ES6, which introduced block-scoped let and const to complement function-scoped var and address issues like unexpected hoisting. Understanding type coercion, the typeof operator, and memory storage distinctions (stack vs. heap) is critical for writing predictable code. Mastering these fundamental concepts is essential for success in JavaScript technical interviews and frontend developer certifications.
JavaScript Variables & Datatypes MCQs
1 min read
Correct Answer: b) BigInt
Explanation:
BigInt is a primitive wrapper added in ES2020 that allows safe storage and operations on large integers beyond Number.MAX_SAFE_INTEGER.
Correct Answer: c) number
Explanation:
Despite standing for 'Not-a-Number', NaN is specified in IEEE 754 floating-point standard as a special numeric value, making its typeof 'number'.
Correct Answer: c) var
Explanation:
Variables declared with 'var' can be re-declared within the same functional or global scope without raising a SyntaxError.
Correct Answer: c) SyntaxError
Explanation:
Const declarations must be initialized during declaration; failing to provide an initial value throws a SyntaxError.
Correct Answer: a) Symbol("id")
Explanation:
Symbols are immutable primitive values. Objects constructed via 'new Number()' are object wrappers, not primitives.
Correct Answer: b) The period between entering scope and variable declaration for let/const where accessing it throws a ReferenceError
Explanation:
TDZ occurs from the start of the block scope until the point where the let/const variable declaration is executed.
Correct Answer: c) object
Explanation:
This is a historical bug from the first version of JavaScript where type tags assigned 000 to object references, and null was represented as a null pointer (0x00).
Correct Answer: b) undefined
Explanation:
Variables declared with let or var without an initial explicit assignment are automatically assigned the default value undefined.
Correct Answer: c) Block scope
Explanation:
The 'let' and 'const' keywords bind variable declarations to the immediate enclosing block context delimited by curly braces {}.
Correct Answer: a) Infinity
Explanation:
In JS IEEE 754 arithmetic operations, dividing a positive number by zero results in global constant numeric value Infinity.
Correct Answer: b) 2^53 - 1
Explanation:
Number.MAX_SAFE_INTEGER (9007199254740991) represents the maximum integer that can be safely and precisely represented in double-precision float.
Correct Answer: b) string
Explanation:
typeof 1 evaluates to string "number". Evaluating typeof "number" yields string "string".
Correct Answer: a) Primitives are stored directly on the execution stack/variable location; reference values store pointers to heap memory addresses
Explanation:
Primitive data types are stored directly in location where variable is bound, while objects reside on heap with memory address references saved in variable slots.
Correct Answer: b) symbol
Explanation:
Symbols have their own dedicated primitive data type identifier in JavaScript called 'symbol'.
Correct Answer: b) false
Explanation:
Due to binary double-precision floating-point arithmetic (IEEE 754), 0.1 + 0.2 evaluates to 0.30000000000000004, which is not strictly equal to 0.3.
Correct Answer: a) var x = 10;
Explanation:
Global declarations using 'var' create properties on the global object (window in browser), whereas global 'let' and 'const' declarations do not.
Correct Answer: c) Mutates successfully without error
Explanation:
The 'const' modifier prevents reassigning the variable identifier reference, but contents of referenced mutable structures like arrays/objects can be altered.
Correct Answer: a) "null"
Explanation:
Explicit string conversion using String() converts the primitive value null directly to string representation "null".
Correct Answer: b) 1
Explanation:
Converting boolean primitive value true to a numeric type coerces it explicitly to integer 1.
Correct Answer: c) NaN
Explanation:
Numeric conversion of value undefined cannot resolve to a valid real number, producing value NaN.
Correct Answer: a) 0
Explanation:
In JavaScript type coercion rules, explicit numerical conversion of null evaluates directly to 0.
Correct Answer: b) true
Explanation:
All objects and arrays in JS (even completely empty ones) are truthy values, evaluating to true when coerced to boolean.
Correct Answer: b) true
Explanation:
Any non-empty string in JS is truthy when converted to boolean, regardless of textual content.
Correct Answer: b) typeof
Explanation:
The 'typeof' unary operator evaluates an expression operand and returns a string indicating its uncoerced primitive type.
Correct Answer: b) 8
Explanation:
Unary minus converts "3" to -3. Subtraction operator forces string "5" to number 5. Calculation evaluates: 5 - (-3) = 8.
Correct Answer: b) 20
Explanation:
Multiplication operator (*) performs numeric coercion on both string operands, converting them into 10 and 2 to produce number 20.
Correct Answer: b) object
Explanation:
Arrays are sub-types of objects in JavaScript; typeof operator returns "object" for array references.
Correct Answer: b) Array.isArray(arr)
Explanation:
Array.isArray() is the standard built-in static method designed specifically to determine whether a given target is an array.
Correct Answer: c) 2ndUser
Explanation:
JavaScript variable identifiers cannot begin with a digit character (0-9).
Correct Answer: b) ReferenceError
Explanation:
In strict mode, assigning a value to an undeclared variable identifier prevents accidental global leak and throws a ReferenceError.
Correct Answer: c) ===
Explanation:
Strict equality operator (===) checks both numeric/primitive value equality and data type without performing implicit coercion.
Correct Answer: a) true
Explanation:
Under loose equality rules (==), null and undefined are specified as loosely equal to each other and to nothing else.
Correct Answer: b) false
Explanation:
Under strict equality (===), null and undefined retain distinct data types ('object' vs 'undefined'), evaluating to false.
Correct Answer: b) function
Explanation:
Even though functions are object subtypes internally, the spec dictates that typeof callable objects returns string "function".
Correct Answer: b) undefined
Explanation:
Accessing non-existent properties on objects returns primitive value undefined.
Correct Answer: b) bigint
Explanation:
The 'n' suffix denotes a BigInt primitive literal; passing it to typeof returns string "bigint".
Correct Answer: a) true
Explanation:
Loose equality (==) coerces numeric representations across Number and BigInt types, confirming their numeric equality.
Correct Answer: b) false
Explanation:
Strict equality (===) fails because BigInt (10n) and Number (10) are different data types.
Correct Answer: c) TypeError
Explanation:
JavaScript prohibits mixing BigInt and standard Number types in arithmetic operations to prevent precision loss; it throws a TypeError.
Correct Answer: c) null
Explanation:
The value null is a primitive representing intentional absence of object value or reference.
Correct Answer: b) FooNaN
Explanation:
Unary plus operator on string "Bar" evaluates to NaN. Concatenating string "Foo" with NaN yields string "FooNaN".
Correct Answer: a) true
Explanation:
![] converts truthy array to false. Expression becomes [] == false. Both sides coerce to number 0 (0 == 0), evaluating to true.
Correct Answer: a) 2
Explanation:
Addition forces numeric coercion of booleans: true becomes 1, false becomes 0. Evaluating: 1 + 1 + 0 = 2.
Correct Answer: c) Returns undefined due to hoisting
Explanation:
'var' declarations are hoisted to top of scope and initialized with undefined immediately during creation phase.
Correct Answer: b) The object identifier reference cannot be reassigned to a new memory address
Explanation:
Const creates an immutable binding reference to target value, but does not render underlying object content immutable.
Correct Answer: a) symbol
Explanation:
Primitive wrapper Symbol constructor returns primitive data type 'symbol'.
Correct Answer: b) undefined
Explanation:
The immediately invoked function expression returns nothing (undefined); typeof undefined evaluates to string "undefined".
Correct Answer: b) Symbol
Explanation:
Symbols are guaranteed unique primitive tokens specifically designed for non-colliding object property keys.
Correct Answer: b) false
Explanation:
Every call to Symbol() produces a totally unique primitive value, even if supplied identical label descriptions.
Correct Answer: a) "number" and true
Explanation:
typeof NaN is string "number". Global function isNaN("abc") converts "abc" to NaN first, returning true.
Correct Answer: a) Global isNaN converts operand to number first; Number.isNaN checks if value is currently NaN without conversion
Explanation:
Number.isNaN() does not perform implicit type coercion; it returns true only if argument is of type Number and equals NaN.
Correct Answer: b) false
Explanation:
Because "abc" is a string data type and Number.isNaN doesn't coerce types, it immediately returns false.
Correct Answer: a) true
Explanation:
Global isNaN coercively casts non-numeric string "abc" to NaN, resulting in true.
Correct Answer: a) true
Explanation:
The loose equality operator (==) coerces string "5" into number 5 prior to comparison.
Correct Answer: b) false
Explanation:
Strict comparison (===) checks data types without conversion; string and number types do not match.
Correct Answer: c) let x = new Number(5);
Explanation:
Using 'new' with constructor wrapper functions creates an Object instance holding primitive value internally.
Correct Answer: b) object
Explanation:
Using constructor function with operator 'new' returns object instance, yielding "object" from typeof.
Correct Answer: a) number
Explanation:
Calling Number() directly as a function without 'new' performs explicit primitive conversion, returning primitive number.
Correct Answer: b) Set
Explanation:
Set is an ES6 reference data type collection structure designed specifically to store unique primitive or reference values.
Correct Answer: a) true
Explanation:
typeof null returns string "object", making strict string equality check evaluate to true.
Correct Answer: c) Symbol
Explanation:
Symbols generate primitive values guaranteed to be completely unique across an entire application runtime.
Correct Answer: a) true
Explanation:
Under loose equality rules, both empty string "" and boolean values coerce to numeric 0.
Correct Answer: b) false
Explanation:
Strict equality comparison fails because operand data types (Number vs String) are not identical.
Correct Answer: a) true
Explanation:
During loose equality, false coerces to number 0, and string "0" coerces to number 0, making 0 == 0 true.
Correct Answer: b) false
Explanation:
Strict equality comparison prevents coercion between Boolean and String types.
Correct Answer: a) boolean
Explanation:
typeof returns lowercase primitive type names; primitive booleans output "boolean".
Correct Answer: b) "33"
Explanation:
Operators evaluate left-to-right: 1 + 2 equals numeric 3. Then numeric 3 + string "3" performs string concatenation to produce "33".
Correct Answer: b) "123"
Explanation:
Left-to-right: "1" + 2 yields string "12". Next, string "12" + 3 concatenates to string "123".
Correct Answer: a) number
Explanation:
Infinity is a numeric property of the global object representing numerical infinity.
Correct Answer: d) 0n
Explanation:
BigInt 0n is a falsy value in JavaScript. Strings like "0", empty arrays [], and empty objects {} are truthy.
Correct Answer: c) 7
Explanation:
JavaScript contains exactly 7 primitive types: Undefined, Null, Boolean, Number, BigInt, String, and Symbol.
Correct Answer: c) Object
Explanation:
Object (including arrays, functions, and maps) is a structural reference data type, not a primitive data type.
Correct Answer: b) undefined
Explanation:
The typeof operator has a special safety feature where operating on an undeclared variable identifier yields string "undefined" without throwing ReferenceError.
Correct Answer: c) ReferenceError
Explanation:
Variables declared with let are hoisted but remain uninitialized in the Temporal Dead Zone (TDZ); accessing them before initialization throws ReferenceError.
Correct Answer: a) undefined
Explanation:
Declarations with var are hoisted to the top of their scope and initialized to value undefined during execution setup.
Correct Answer: a) 1
Explanation:
Unary plus operator (+) forces type conversion of boolean operand true to numeric value 1.
Correct Answer: a) 0
Explanation:
Unary plus operator (+) forces type conversion of boolean operand false to numeric value 0.
Correct Answer: a) 0
Explanation:
Unary plus operator (+) coerces empty string literal "" to number 0.
Correct Answer: a) NaN
Explanation:
Unary plus operator (+) fails to convert non-numeric text string "Hello" to valid number, returning NaN.
Correct Answer: b) Individual character values within an existing string primitive instance cannot be altered directly
Explanation:
Primitive string values are immutable; operations that alter strings return newly generated string primitives.
Correct Answer: b) "hello"
Explanation:
Primitives are immutable. Direct bracket index assignments on primitive strings fail silently (or throw TypeError in strict mode) leaving the original unchanged.
Correct Answer: a) bigint
Explanation:
100n is a BigInt primitive value, so calling typeof returns string identifier "bigint".
Correct Answer: b) Variables hold values, and types are associated with values rather than the variables themselves
Explanation:
JavaScript is dynamically typed, meaning variables can be reassigned values of completely different data types during execution.
Correct Answer: b) string
Explanation:
Reassigning variable identifier x to string "hello" changes the type of value stored in x to string.
Correct Answer: a) Number.MIN_SAFE_INTEGER
Explanation:
Number.MIN_SAFE_INTEGER represents -(2^53 - 1), or -9007199254740991.
Correct Answer: b) The smallest positive floating point number greater than 0
Explanation:
Number.MIN_VALUE is approximately 5e-324, representing smallest positive value closest to zero, not most negative number.
Correct Answer: c) object
Explanation:
Math is a built-in standard global namespace Object holding mathematical properties and methods.
Correct Answer: a) number
Explanation:
Math.PI holds standard double-precision floating point number primitive, returning "number".
Correct Answer: a) -Infinity
Explanation:
JavaScript supports signed zeroes (-0 and +0); dividing positive 1 by -0 yields numeric -Infinity.
Correct Answer: b) false
Explanation:
Object.is static method distinguishes signed zeros, evaluating Object.is(-0, +0) to false.
Correct Answer: a) true
Explanation:
The strict equality operator (===) explicitly treats signed zeros -0 and +0 as equal values.
Correct Answer: a) true
Explanation:
Unlike triple equals (===), Object.is evaluates NaN values as identical to each other, returning true.
Correct Answer: b) false
Explanation:
In IEEE 754 and JavaScript equality semantics, NaN is unequal to any value including itself.
Correct Answer: b) let
Explanation:
The 'let' keyword specifies block scoping rules, isolating variables inside block boundaries.
Correct Answer: a) 5
Explanation:
Variables declared using 'var' ignore arbitrary block enclosures `{}` and leak to enclosing function or global scope.
Correct Answer: b) ReferenceError
Explanation:
Because 'let' is block-scoped, variable `a` is inaccessible outside enclosing block bounds, throwing ReferenceError.
Correct Answer: b) object
Explanation:
JSON is a global namespace object in JavaScript containing methods like parse() and stringify().
Correct Answer: a) Outputs 2
Explanation:
The const declaration prevents reassigning the identifier binding `obj`, but object properties remain fully mutable.
Correct Answer: b) Throws TypeError
Explanation:
Reassigning a variable declared with const to a new object memory reference throws a TypeError.
Correct Answer: a) true
Explanation:
Relational comparison operators force string "2" to number 2, making numeric evaluation 2 > 1 return true.
Correct Answer: a) true
Explanation:
When comparing two strings, JavaScript performs lexicographical comparison based on character Unicode values. "2" comes after "1", making "2" > "12" true.
Related Posts

Latest C++ Basics MCQs
Created by Bjarne Stroustrup as an extension of the C programming language, C++ is a powerful, high-performance, statically typed language…
October 19, 2026By MCQs Generator

Java Control Flow / If Else MCQs
Control flow statements in Java determine the exact order in which code instructions and expressions execute during runtime. By default,…
October 19, 2026By MCQs Generator

JavaScript Functions MCQs
Functions are the primary building blocks of JavaScript applications, enabling code modularity, encapsulation, and reuse. In JavaScript, functions are first-class…
October 19, 2026By MCQs Generator
Related Categories

AI & Data Science MCQ
5 topics
By MCQs Generator

Arts & Humanities MCQ
4 topics
By MCQs Generator

Civil Engineering MCQ
4 topics
By MCQs Generator

Commerce & Business MCQ
4 topics
By MCQs Generator

Competitive Exams MCQ
5 topics
By MCQs Generator

Electrical & Electronics Engineering MCQ
3 topics
By MCQs Generator

General Knowledge MCQ
2 topics
By MCQs Generator

General Science MCQ
4 topics
By MCQs Generator

Law & Judiciary MCQ
3 topics
By MCQs Generator

Mechanical Engineering MCQ
4 topics
By MCQs Generator

Medical & Health Sciences MCQ
4 topics
By MCQs Generator

Modern Tech Fields MCQ
3 topics
By MCQs Generator