reactjs-interview-questions
List of top 500 ReactJS Interview Questions & Answers....Coding exercise questions are coming soon!!
- 45k
- JavaScript
- MIT
JavaScript Basics
Repo learning-zone/javascript-basics, read from GitHub 1 min ago. learning-zone has not joined Take My Repo.
learning-zone/javascript-basics is a public repo on GitHub by learning-zone. JavaScript Basics. It declares no license on GitHub. Public does not mean open source: without a license, nobody is granted the right to reuse it. It is written mainly in HTML, has 1,876 stars and last changed on 2026-05-27. Nobody has reviewed it on Take My Repo yet, which says nothing about its quality. Read from GitHub on 2026-11-18.
In the maintainer's words. Shown from GitHub; Take My Repo does not keep a copy.
Click ★ if you like the project. Your contributions are heartily ♡ welcome.
Focus: Syntax, basic logic, and standard data handling.
Focus: ES6+ features, DOM, and common "trick" concepts.
Focus: Asynchronous operations, performance, and internal engine mechanics. [4]
Focus: Scalability, security, and low-level optimization.
Focus: Code review, team standards, architectural decisions, and engineering best practices for leading a development team.
Focus: System-level design, scalability, security posture, micro-frontend, and cross-team JavaScript architecture.
1. Template Strings:
Template literals are string literals allowing embedded expressions.
Benefits:
// String Substitution let name = `Abhinav Sharma`; console.log(`Hi, ${name}`); // Output: "Hi, Abhinav Sharma" // Multiline String let msg = `Hello \n World`; console.log(`${msg}`); // Output: "Hello World"
⚝ Try this example on CodeSandbox
2. Spread Operator:
Spread operator allows iterables( arrays / objects / strings ) to be expanded into single arguments/elements.
function sum(x, y, z) { return x + y + z; } const numbers = [10, 20, 30]; // Using Apply (ES5) console.log(sum.apply(null, numbers)); // 60 // Using Spread Operator console.log(sum(...numbers)); // 60
⚝ Try this example on CodeSandbox
2.1. Copying an array:
const fruits = ["Apple", "Orange", "Banana"]; const newFruitArray = [...fruits]; console.log(newFruitArray);
Output:
['Apple', 'Orange', 'Banana']
⚝ Try this example on CodeSandbox
2.2. Concatenating arrays:
const arr1 = ["A", "B", "C"]; const arr2 = ["X", "Y", "Z"]; const result = [...arr1, ...arr2]; console.log(result);
Output:
['A', 'B', 'C', 'X', 'Y', 'Z']
⚝ Try this example on CodeSandbox
2.3. Spreading elements together with an individual element:
const fruits = ["Apple", "Orange", "Banana"]; const newFruits = ["Cherry", ...fruits]; console.log(newFruits);
Output:
['Cherry', 'Apple', 'Orange', 'Banana']
⚝ Try this example on CodeSandbox
2.4. Spreading elements on function calls:
const fruits = ["Apple", "Orange", "Banana"]; const getFruits = (f1, f2, f3) => { console.log(`Fruits: ${f1}, ${f2} and ${f3}`); }; getFruits(...fruits);
Output:
Fruits: Apple, Orange and Banana
⚝ Try this example on CodeSandbox
2.5. Spread syntax for object literals:
const obj1 = { id: 101, name: 'Rajiv Sandal' } const obj2 = { age: 35, country: 'INDIA' } const employee = { ...obj1, ...obj2 } console.log(employee);
Output:
{ "id": 101, "name": "Rajiv Sandal", "age": 35, "country": "INDIA" }
3. Sets:
Sets are a new object type with ES6 (ES2015) that allow to create collections of unique values. The values in a set can be either simple primitives like strings or integers, but more complex object types like object literals or arrays can also be part of a set.
const numbers = new Set([10, 20, 20, 30, 40, 50]); console.log(numbers); Set(5) { 10, 20, 30, 40, 50 } console.log(typeof numbers); // Object
⚝ Try this example on CodeSandbox
4. Default Parametrs:
function add(x = 10, y = 20) { console.log(x + y); } add(10, 30); // Output: 10 + 30 = 40 add(15); // Output: 15 + 20 = 35 add(); // Output: 10 + 20 = 30
⚝ Try this example on CodeSandbox
5. repeat():
The repeat() method constructs and returns a new string which contains the specified number of copies of the string on which it was called, concatenated together.
const msg = "Hello World \n"; console.log(`${msg.repeat(3)}`);
Output:
Hello World Hello World Hello World
⚝ Try this example on CodeSandbox
6. Arrow Function (=>):
const add = (x, y) => x + y; console.log(add(10, 20)); // 30
⚝ Try this example on CodeSandbox
7. Arrow function with this
/** * Using Arrow function */ const person = { name: "Diksha", actions: ["bike", "hike", "ski"], printActions() { this.actions.forEach((action) => { console.log(this.name + " likes to " + action); }); }, }; person.printActions();
Output:
Diksha likes to bike Diksha likes to hike Diksha likes to ski
⚝ Try this example on CodeSandbox
8. Destructing Assignment:
// Destructing Assignment const { title, price, description } = { title: "iPhone", price: 999, description: "The iPhone is a smartphone developed by Apple" }; console.log(title); // iPhone console.log(price); // 999 console.log(description); // The iPhone is a smartphone developed by Apple
⚝ Try this example on CodeSandbox
9. Generators:
A generator is a function that can stop midway and then continue from where it stopped. In short, a generator appears to be a function but it behaves like an iterator.
function* generator(num) { yield num + 10; yield num + 20; yield num + 30; } const gen = generator(10); console.log(gen.next().value); // 20 console.log(gen.next().value); // 30 console.log(gen.next().value); // 40
⚝ Try this example on CodeSandbox
10. Symbols:
They are tokens that serve as unique IDs. We create symbols via the factory function Symbol(). Symbols primary use case is for making private object properties, which can be only of type String or Symbol (Numbers are automatically converted to Strings).
const symbol1 = Symbol(); const symbol2 = Symbol(42); const symbol3 = Symbol("Hi"); console.log(typeof symbol1); // symbol console.log(symbol3.toString()); // Symbol(Hi) console.log(Symbol("Hi") === Symbol("Hi")); // false
⚝ Try this example on CodeSandbox
11. Iterator:
The iterable is a interface that specifies that an object can be accessible if it implements a method who is key is [symbol.iterator].
const title = "ES6"; const iterateIt = title[Symbol.iterator](); console.log(iterateIt.next().value); //output: E console.log(iterateIt.next().value); //output: S console.log(iterateIt.next().value); //output: 6
⚝ Try this example on CodeSandbox
Global variables are declared outside of a function or declared with a window object for accessibility throughout the program (unless shadowed by locals). If you declare a variable without using var, even if it's inside a function, it will still be seen as global.
The var statement declares a function-scoped or globally-scoped variable, optionally initializing it to a value.
Example:
var x = 10; if (x === 10) { var x = 20; console.log(x); // expected output: 20 } console.log(x); // expected output: 20
Example: Declaring global variable within function
window.value = 90; // Declaring global variable by window object function setValue() { window.value = 100; } // Accessing global variable from other function function getValue() { setValue(); return window.value; } console.log(getValue()); // 100
Using Undeclared Variables:
let, const, or var, you'll end up creating a new global variable. It will be global no matter how deeply nested within functions and blocks your code is, which is almost certainly not what you want, is bug-prone, and is one of the best reasons for using strict mode!var: they define properties of the global object. But unlike the properties defined by proper var declarations, these properties can be deleted with the delete operator.⚝ Try this example on CodeSandbox
Template literals help make it simple to do string interpolation, or to include variables in a string.
const person = { name: 'Tyler', age: 28 }; console.log(`Hi, my name is ${person.name} and I am ${person.age} years old!`); // 'Hi, my name is Tyler and I am 28 years old!'
Template literals, however, preserve whatever spacing you add to them. For example, to create that same multi-line output that we created above, you can simply do:
console.log(`This is line one. This is line two.`); // This is line one. // This is line two.
Another use case of template literals would be to use as a substitute for templating libraries for simple variable interpolations:
const person = { name: 'Tyler', age: 28 }; document.body.innerHTML = ` <div> <p>Name: ${person.name}</p> <p>Name: ${person.age}</p> </div> `
let, var or const?Variables declared using the var keyword are scoped to the function in which they are created, or if created outside of any function, to the global object. let and const are block scoped, meaning they are only accessible within the nearest set of curly braces (function, if-else block, or for-loop).
/** * All variables are accessible within functions. */ function variableScope() { var x = 10; let y = 20; const z = 30; console.log(x); // 10 console.log(y); // 20 console.log(z); // 30 } console.log(x); // ReferenceError: x is not defined console.log(y); // ReferenceError: y is not defined console.log(z); // ReferenceError: z is not defined variableScope();
/** * var declared variables are accessible anywhere in the function scope. */ if (true) { var a = 10; let b = 20; const c = 30; } console.log(a); // 10 console.log(b); // ReferenceError: b is not defined console.log(c); // ReferenceError: c is not defined
var allows variables to be hoisted, meaning they can be referenced in code before they are declared. let and const will not allow this, instead throwing an error.
console.log(a); // undefined var a = 'foo'; console.log(b); // ReferenceError: can\'t access lexical declaration 'b' before initialization let b = 'baz'; console.log(c); // ReferenceError: can\'t access lexical declaration 'c' before initialization const c = 'bar';
Redeclaring a variable with var will not throw an error, but 'let' and 'const' will.
var a = 'foo'; var a = 'bar'; console.log(a); // "bar" let b = 'baz'; let b = 'qux'; // Uncaught SyntaxError: Identifier 'b' has already been declared
let and const differ in that let allows reassigning the variable's value while const does not.
// This is ok. let a = 'foo'; a = 'bar'; console.log(a); // bar // This causes an exception. const b = 'baz'; b = 'qux'; console.log(b) // TypeError: Assignment to constant variable.
⚝ Try this example on CodeSandbox
The double exclamation mark (!!) in JavaScript forces any value into its corresponding strict boolean representation (true or false). The !! (double negation) operator converts any value to its boolean equivalent:
! negates the value (converting it to a boolean)! negates it again, giving the true boolean representationExample:
console.log(!!0); // false console.log(!!""); // false console.log(!!null); // false console.log(!!undefined); // false console.log(!!NaN); // false console.log(!!1); // true console.log(!!"text"); // true console.log(!!{}); // true console.log(!![]); // true
Note: It's commonly used to explicitly cast a value to boolean without using Boolean(value).
var x = 1 and x = 1?The primary difference is that var x = 1 explicitly declares a function-scoped or globally-scoped variable, whereas x = 1 assigns a value to an identifier without declaring it, which can lead to global scope pollution or runtime errors depending on your code's strictness mode
var x = 1:
var inside a { } block can be accessed from outside the block.var inside a function are not accessible (visible) from outside the function.var will not trigger an error, even in strict mode, and the variable will not lose its value unless another assignment is performed.Example:
var x = 1; if (x === 1) { var x = 2; console.log(x); // expected output: 2 } console.log(x); // expected output: 2
var x = 5; // global function someThing(y) { var x = 3; // local var z = x + y; console.log(z); } someThing(4); // 7 console.log(x); // 5
x = 1:
x = 1 is accessible in: (Block scope - Function scope - Global scope)let, const, or var, you'll end up creating a new global variable. It will be global no matter how deeply nested within functions and blocks your code is, which is almost certainly not what you want, is bug-prone, and is one of the best reasons for using strict mode!var they define properties of the global object.var declarations, these properties can be deleted with the delete operator.Example:
var x = 5; // global function someThing(y) { x = 1; // still global! var z = x + y; console.log(z); } someThing(4) // 5 console.log(x) // 1
Example:
{ console.log(x + y); // NaN var x = 1; var y = 2; }
{ console.log(x + y); // Uncaught ReferenceError: x is not defined x = 1; y = 2; }
| var x = 1 | x = 1 | |
|---|---|---|
| Strict mode | ✔ | ❌ |
| Block scope | ❌ | ✔ |
| Function scope | ✔ | ✔ |
| Global scope | ✔ | ✔ |
| Hoisting | ✔ | ❌ |
| Reassigning | ✔ | ✔ |
In JavaScript, you can assign default values to variables using several modern and legacy approaches, depending on the exact conditions you want to check.
1. OR operator (||)
let name = userInput || "Default"; // Uses "Default" if userInput is falsy (0, "", null, undefined, false)
2. Nullish coalescing (??) (preferred)
let name = userInput ?? "Default"; // Uses "Default" only if userInput is null or undefined (not 0 or "")
3. Destructuring defaults
const { name = "John", age = 25 } = user; const [first = 0, second = 0] = arr;
4. Function parameter defaults
function greet(name = "World") { return `Hello, ${name}!`; } greet(); // "Hello, World!" greet("Alice"); // "Hello, Alice!"
5. Logical OR assignment (||=)
let x = null; x ||= "default"; // x = "default"
6. Nullish assignment (??=)
let x = 0; x ??= "default"; // x stays 0 (not null/undefined)
Key difference between || and ??:
let count = 0; count || 10; // 10 — 0 is falsy, so falls back count ?? 10; // 0 — 0 is not null/undefined, so keeps it
Note: Use ?? when 0, "", or false are valid values.
Local variables always take precedence over global variables within their scope.
let x = "global"; function example() { let x = "local"; console.log(x); // "local" — local shadows the global } example(); console.log(x); // "global" — unchanged
Scope chain — JavaScript looks up variables from innermost to outermost:
let x = "global"; function outer() { let x = "outer"; function inner() { let x = "inner"; console.log(x); // "inner" } inner(); console.log(x); // "outer" } outer(); console.log(x); // "global"
If no local variable exists, it walks up the chain:
let x = "global"; function example() { console.log(x); // "global" — no local x, found in outer scope }
Shadowing pitfall:
let x = "global"; function example() { console.log(x); // ReferenceError (TDZ) — let/const are hoisted but not initialized let x = "local"; }
Precedence order (innermost → outermost):
window / globalThis)⚝ Try this example on CodeSandbox
Variable shadowing occurs when a variable declared within a certain scope (decision block, method, or inner class) has the same name as a variable declared in an outer scope. This outer variable is said to be shadowed.
If there is a variable in the global scope, and you'd like to create a variable with the same name in a function. The variable in the inner scope will temporarily shadow the variable in the outer scope.
Example:
let x = "global"; function example() { let x = "local"; // shadows the global x console.log(x); // "local" } example(); console.log(x); // "global" — outer x is unaffected
Block-level shadowing (let/const):
let msg = "outside"; if (true) { let msg = "inside"; // shadows outer msg console.log(msg); // "inside" } console.log(msg); // "outside"
var does NOT shadow at block level (only at function level):
var msg = "outside"; if (true) { var msg = "inside"; // overwrites, not shadows! console.log(msg); // "inside" } console.log(msg); // "inside" — original was overwritten!
Nested function shadowing:
let value = 1; function outer() { let value = 2; // shadows global function inner() { let value = 3; // shadows outer console.log(value); // 3 } inner(); console.log(value); // 2 } outer(); console.log(value); // 1
Note:
let/const shadow at block level; var only at function levelThe scope chain is the mechanism JavaScript uses to resolve variable references by searching through nested scopes from innermost to outermost until the variable is found (or a ReferenceError is thrown).
Example::
let globalVar = "I'm a global variable"; function outer() { let outerVar = "I'm an outer variable"; function inner() { let innerVar = "I'm an inner variable"; console.log(innerVar); // "I'm an inner variable" console.log(outerVar); // "I'm an outer variable" console.log(globalVar); // "I'm a global variable" } inner(); } outer();
Note:
There are eight basic data types in JavaScript.
| Data Types | Description | Example |
|---|---|---|
| String | Represents textual data | let str = 'Hi', let str2 = "Hello", let str3 = `Hello World` |
| Number | An integer or a floating-point number | let num = 3, let num2 = 3.234, let num3 = 3e-2 |
| BigInt | An integer with arbitrary precision | let num = 900719925124740999n, let num = 1n |
| Boolean | Any of two values: true or false | let flag = true |
| undefined | A data type whose variable is not initialized | let a; |
| null | Denotes a null value | let a = null; |
| Symbol | Data type whose instances are unique and immutable | let value = Symbol('hello'); |
| Object | key-value pairs of collection of data | let student = { }; |
String:
String is used to store text. In JavaScript, strings are surrounded by quotes:
Example::
// Strings const firstName = "Mukul"; const lastName = "Mittal"; const result = `Name: ${firstName} ${lastName}`; console.log(result); // Name: Mukul Mittal console.log(typeof result); // string
Number:
Number represents integer and floating numbers (decimals and exponentials). A number type can also be +Infinity, -Infinity, and NaN (not a number).
const number1 = 3; const number2 = 3.433; const number3 = 3e5; // 3 * 10^5 const number4 = 3 / 0; console.log(number4); // Infinity console.log(typeof number4) // number const number5 = -3 / 0; console.log(number5); // -Infinity console.log(typeof number5); // number // strings can\'t be divided by numbers const number6 = "abc" / 3; console.log(number6); // NaN console.log(typeof number6); // number
BigInt:
In JavaScript, Number type can only represent numbers less than (253 - 1) and more than -(253 - 1). However, if you need to use a larger number than that, you can use the BigInt data type.
A BigInt number is created by appending n to the end of an integer.
// BigInt value const num1 = 100000000000000000n; const num2 = 1000000000000000000n; const num3 = 10; // Adding two big integers const result1 = num1 + num2; console.log(result1); // "1100000000000000000n" console.log(typeof result1); // bigint // Error! BitInt and number cannot be added const result2 = num1 + num2 + num3; console.log(result2); // Uncaught TypeError: Cannot mix BigInt and other types console.log(typeof result2); // Uncaught TypeError: Cannot mix BigInt and other types
Boolean:
This data type represents logical entities. Boolean represents one of two values: true or false.
const dataChecked = true; const valueCounted = false;
undefined:
The undefined data type represents value that is not assigned. If a variable is declared but the value is not assigned, then the value of that variable will be undefined.
let name; console.log(name); // undefined let name = undefined; console.log(name); // undefined
null:
In JavaScript, null is a special value that represents empty or unknown value.
const number = null;
Symbol:
A value having the data type Symbol can be referred to as a symbol value. Symbol is an immutable primitive value that is unique.
// Two symbols with the same description const value1 = Symbol('hello'); const value2 = Symbol('hello'); let result = (value1 === value2) ? true : false; // false; // Note: Though value1 and value2 both contain 'hello', they are different as they are of the Symbol type.
Object:
An object is a complex data type that allows us to store collections of data.
const employee = { firstName: 'John', lastName: 'K', email: 'john.k@gmail.com' };
undefined property?The undefined property indicates that a variable has not been assigned a value, or not declared at all. The type of undefined value is undefined too.
var user; // Value is undefined, type is undefined console.log(typeof(user)) //undefined
Any variable can be emptied by setting the value to undefined.
user = undefined
null vs undefined?Null:
Null means an empty or non-existent value. Null is assigned, and explicitly means nothing.
var test = null; console.log(test); // null
null is also an object. Interestingly, this was actually an error in the original JavaScript implementation:
console.log(typeof test); // object
Undefined:
Undefined means a variable has been declared, but the value of that variable has not yet been defined. For example:
var test2; console.log(test2); // undefined
Unlike null, undefined is of the type undefined:
console.log(typeof test2); // undefined
Difference:
| Null | Undefined |
|---|---|
| It is an assignment value which indicates that variable points to no object. | It is not an assignment value where a variable has been declared but has not yet been assigned a value. |
| Type of null is object | Type of undefined is undefined |
| The null value is a primitive value that represents the null, empty, or non-existent reference. | The undefined value is a primitive value used when a variable has not been assigned a value. |
| Indicates the absence of a value for a variable | Indicates absence of variable itself |
| Converted to zero (0) while performing primitive operations | Converted to NaN while performing primitive operations |
Type coercion is the automatic or implicit conversion of values from one data type to another (such as strings to numbers). Type conversion is similar to type coercion because they both convert values from one data type to another with one key difference — type coercion is implicit whereas type conversion can be either implicit or explicit.
Example:
const value1 = '10'; const value2 = 20; let sum = value1 + value2; console.log(sum);
In the above example, JavaScript has coerced the 10 from a number into a string and then concatenated the two values together, resulting in a string of 1020. JavaScript had a choice between a string or a number and decided to use a string.
// Example of explicit coercion const value1 = '10'; const value2 = 20; let sum = Number(value1) + value2; console.log(sum);
An operator is capable of manipulating (mathematical and logical computations) a certain value or operand. There are various operators supported by JavaScript as below,
Arithmetic Operators:
Arithmetic operators are used to perform mathematical operations between numeric operands.
| Operators | Description | Example ( say let x = 10, y = 20;) |
|---|---|---|
| + | Adds two numeric operands. | x + y |
| - | Subtract right operand from left operand | y - x |
| * | Multiply two numeric operands. | x * y |
| / | Divide left operand by right operand. | y / x |
| % | Modulus operator. Returns remainder of two operands. | x % 2 |
| ++ | Increment operator. Increase operand value by one. | x++ |
| -- | Decrement operator. Decrease value by one. | x-- |
Comparison Operators:
JavaScript provides comparison operators that compare two operands and return a boolean value true or false.
| Operators | Description |
|---|---|
| == | Compares the equality of two operands without considering type. |
| === | Compares equality of two operands with type. |
| != | Compares inequality of two operands. |
| > | Returns a boolean value true if the left-side value is greater than the right-side value; otherwise, returns false. |
| < | Returns a boolean value true if the left-side value is less than the right-side value; otherwise, returns false. |
| >= | Returns a boolean value true if the left-side value is greater than or equal to the right-side value; otherwise, returns false. |
| <= | Returns a boolean value true if the left-side value is less than or equal to the right-side value; otherwise, returns false. |
Logical Operators:
The logical operators are used to combine two or more conditions.
1. && - is known as AND operator. It checks whether two operands are non-zero or not (0, false, undefined, null or "" are considered as zero). It returns 1 if they are non-zero; otherwise, returns 0
2. || - is known as OR operator. It checks whether any one of the two operands is non-zero or not (0, false, undefined, null or "" is considered as zero). It returns 1 if any one of of them is non-zero; otherwise, returns 0.
3. ! - is known as NOT operator. It reverses the boolean result of the operand (or condition). !false returns true, and !true returns false.
Assignment Operators:
The assignment operators to assign values to variables with less key strokes.
| Operators | Description |
|---|---|
| = | Assigns right operand value to the left operand. |
| += | Sums up left and right operand values and assigns the result to the left operand. |
| -= | Subtract right operand value from the left operand value and assigns the result to the left operand. |
| *= | Multiply left and right operand values and assigns the result to the left operand. |
| /= | Divide left operand value by right operand value and assign the result to the left operand. |
| %= | Get the modulus of left operand divide by right operand and assign resulted modulus to the left operand. |
Below are the list of bit-wise logical operators used in JavaScript
| Operator | Usage | Description |
|---|---|---|
| Bitwise AND | a & b | Returns a one in each bit position for which the corresponding bits of both operands are ones. |
| Bitwise OR | a | b |
| Bitwise XOR | a ^ b | Returns a one in each bit position for which the corresponding bits of either but not both operands are ones. |
| Bitwise NOT | ~ a | Inverts the bits of its operand. |
| Left shift | a << b | Shifts a in binary representation b (< 32) bits to the left, shifting in zeroes from the right. |
| Sign-propagating right shift | a >> b | Shifts a in binary representation b (< 32) bits to the right, discarding bits shifted off. |
| Zero-fill right shift | a >>> b | Shifts a in binary representation b (< 32) bits to the right, discarding bits shifted off, and shifting in zeroes from the left. |
Examples:
| Operation | Result | Same as | Result |
|---|---|---|---|
| 5 & 1 | 1 | 0101 & 0001 | 0001 |
| `5 | 1` | 5 | 0101 |
~ 5 |
-6 | ~0101 | 1010 |
5 << 1 |
10 | 0101 << 1 | 1010 |
5 ^ 1 |
4 | 0101 ^ 0001 | 0100 |
5 >> 1 |
2 | 0101 >> 1 | 0010 |
| 5 >>> 1 | 2 | 0101 >>> 1 | 0010 |
⚝ Try this example on CodeSandbox
== and === operators?JavaScript provides both strict (===, !==) and type-converting (==, !=) equality comparison. The strict operators takes type of variable in consideration, while non-strict operators make type correction/conversion based upon values of variables. The strict operators follow the below conditions for different types,
===, but equal with ==. i.e,
null === undefined --> false but null == undefined --> trueExample:
0 == false // true 0 === false // false 1 == "1" // true 1 === "1" // false null == undefined // true null === undefined // false "0" == false // true "0" === false // false [] === [] // false, refer different objects in memory {} === {} // false, refer different objects in memory
⚝ Try this example on CodeSandbox
In JavaScript, the typeof operator returns the data type of its operand in the form of a string. The operand can be any object, function, or variable.
Example:
console.log(typeof undeclaredVariable); // "undefined" let a; console.log(typeof a); // "undefined" const b = "Hello World"; console.log(typeof b); // "string" const c = 42; console.log(typeof c); // "number" const d = 3.1415; console.log(typeof d); // "number" const e = true; console.log(typeof e); // "boolean" const f = null; console.log(typeof f); // "object" const g = undefined; console.log(typeof g); // "undefined" const h = { b: "c" }; console.log(typeof h); // "object" const i = function () { return 10; }; console.log(typeof i); // "function"
⚝ Try this example on CodeSandbox
The unary(+) operator is used to convert a variable to a number. If the variable cannot be converted, it will still become a number but with the value NaN.
Example:
var x = "100"; var y = +x; console.log(typeof x, typeof y); // string, number var a = "Hello"; var b = +a; console.log(typeof a, typeof b, b); // string, number, NaN
⚝ Try this example on CodeSandbox
The delete keyword is used to delete the property as well as its value.
Example:
const user = { name: "Sadhika Chaudhuri", age: 24 }; delete user.age; console.log(user); // { name: "Sadhika Chaudhuri" }
The conditional (ternary) operator is the only JavaScript operator that takes three operands which acts as a shortcut for if statement.
Syntax:
<condition> ? <value1> : <value2>;
Example:
const isAuthenticated = false; console.log(isAuthenticated ? 'Hello, welcome' : 'Sorry, you are not authenticated');
Yes, you can apply chaining on conditional operator similar to if … else if … else if … else chain.
Example:
function getValue(someParam) { return condition1 ? value1 : condition2 ? value2 : condition3 ? value3 : value4; } // The above conditional operator is equivalent to: function getValue(someParam) { if (condition1) { return value1; } else if (condition2) { return value2; } else if (condition3) { return value3; } else { return value4; } }
typeof and instanceof operator?The typeof operator checks if a value has type of primitive type which can be one of boolean, function, object, number, string, undefined, symbol, or bigint.
Example:
const x = "Hello World"; const y = new String("Hello World"); typeof x; // returns 'string' typeof y; // returns 'object'
The instanceof is a binary operator, accepting an object and a constructor. It returns a boolean indicating whether or not the object has the given constructor in its prototype chain.
const a = "Hello World"; const b = new String("Hello World"); a instanceof String; // returns false b instanceof String; // returns true
⚝ Try this example on CodeSandbox
[...'Hello']
Output: ['H', 'e', 'l', 'l', 'o']
Explanation: The string is an iterable type and the spread operator with in an array maps every character of an iterable to one element. Hence, each character of a string becomes an element within an Array.
??) in JavaScript?The nullish coalescing operator (??) returns the right-hand side operand when the left-hand side operand is null or undefined. Otherwise, it returns the left-hand side operand. Unlike ||, it does not treat 0, false, or "" as falsy.
Syntax:
leftExpr ?? rightExpr
Example:
console.log(null ?? 'default'); // 'default' console.log(undefined ?? 'default'); // 'default' console.log(0 ?? 'default'); // 0 (0 is NOT null/undefined) console.log('' ?? 'default'); // '' (empty string is NOT null/undefined) console.log(false ?? 'default'); // false // Practical use: provide a fallback for a missing config value const config = { timeout: 0 }; const timeout = config.timeout ?? 3000; console.log(timeout); // 0 (not 3000, because 0 is a valid value)
Nullish coalescing assignment (??=):
let user = { name: null }; user.name ??= 'Anonymous'; console.log(user.name); // 'Anonymous'
Logical assignment operators (ES2021) combine a logical operator with assignment. There are three:
| Operator | Equivalent to | Description |
|---|---|---|
&&= |
a && (a = b) |
Assigns b to a only if a is truthy |
||= |
a || (a = b) |
Assigns b to a only if a is falsy |
??= |
a ?? (a = b) |
Assigns b to a only if a is null or undefined |
Example:
// &&= (AND assignment) let a = 1; a &&= 2; console.log(a); // 2 (a was truthy, so assigned) let b = 0; b &&= 2; console.log(b); // 0 (b was falsy, not assigned) // ||= (OR assignment) let c = null; c ||= 'default'; console.log(c); // 'default' (c was falsy) let d = 'existing'; d ||= 'default'; console.log(d); // 'existing' (d was truthy, not reassigned) // ??= (Nullish assignment) let e = null; e ??= 'fallback'; console.log(e); // 'fallback' let f = 0; f ??= 'fallback'; console.log(f); // 0 (0 is not null/undefined)
The Math.random() function returns a floating-point, pseudo-random number in the range 0 to less than 1 (inclusive of 0, but not 1). For example, if you want generate random integers between 1 to 100, the multiplication factor should be 100,
// Example 01: Math.random(); // returns a random integer between 0 to 1 // Example 02: Math.floor(Math.random() * 100) + 1; // returns a random integer from 1 to 100 // Example 03: function getRandomNumber(max) { return Math.floor(Math.random() * max) + 1; } console.log(getRandomNumber(10)); // returns a random integer from 1 to 10
Random integer between min and max (inclusive):
function randomInt(min, max) { return Math.floor(Math.random() * (max - min + 1)) + min; } console.log(randomInt(1, 6)); // simulates a dice roll: 1–6
⚝ Try this example on CodeSandbox
The isNaN() function determines whether a value is NaN ( Not a Number ) or not. This function returns true if the value equates to NaN. The isNaN() method converts the value to a number before testing it.
Example:
isNaN('Hello') // true isNaN('100') // false typeof NaN // Number Number.isNaN('Hello'); // false
⚝ Try this example on CodeSandbox
The global isFinite() function determines whether the passed value is a finite number. It returns false if the value is +infinity, -infinity, or NaN (Not-a-Number), otherwise it returns true.
isFinite(Infinity); // false isFinite(NaN); // false isFinite(-Infinity); // false isFinite(100); // true isFinite(1/0); // false Number.isFinite(0 / 0); // false Number.isFinite(null); // false Number.isFinite("123") // false
⚝ Try this example on CodeSandbox
The Number.NEGATIVE_INFINITY property represents the negative Infinity value.
Syntax:
Number.NEGATIVE_INFINITY
/** * NEGATIVE_INFINITY */ console.log(-10/0); // -Infinity console.log(Number.NEGATIVE_INFINITY); // -Infinity console.log(Number.MAX_VALUE + Number.MAX_VALUE); // Infinity console.log(-2 * Number.MAX_VALUE); // -Infinity console.log("Math.pow(10, 1000): " + Math.pow(10, 1000)); // Infinity console.log("Math.log(0): " + Math.log
learning-zone/javascript-basics is a public repo on GitHub by learning-zone. JavaScript Basics.
It declares no license on GitHub. Public does not mean open source: without a license, nobody is granted the right to reuse it.
Its maker has not tagged a system, so it is unknown here. Its README says what it needs.
Open "Take it" on its page: Take My Repo writes an install plan for your machine and hands it to your AI agent (Claude Code, Codex or Cursor), which asks you before each step. Take My Repo has not tested it on any machine.
Its last change on GitHub was on 2026-05-27. Take My Repo does not judge from that whether it is maintained.
Nobody has reviewed it on Take My Repo yet, which says nothing about its quality.
List of top 500 ReactJS Interview Questions & Answers....Coding exercise questions are coming soon!!
Learn JavaScript from scratch in 30 days with 30 hands-on projects. A free, open source, beginner-friendly course covering variables to async/await, the DOM, and OOP.
List of 1000 JavaScript Interview Questions
Top JavaScript interview questions and answers for Frontend Engineers (updated for 2026)
A collection of JavaScript modern interview code challenges for beginners to experts
This page is also available as structured data, with the same sources and dates.
/api/v1/resources/gh/learning-zone/javascript-basicsTake My Repo has not tested this on your machine. Requirements come from the project's own documentation.