This is a Question Bank, not a Study Material.

Other materials to consider

HTML interview questions

CSS interview questions

Angular Interview Questions

Event Loop

Macro and Micro Tasks

Promises — Basics

Hoisting

this keyword in JS

Closure

Data Types

JavaScript has several basic data types, which can be categorized into two main categories: primitive data types and reference data types. Here's a list and description of the basic data types in JavaScript:

Primitive Data Types:

  1. Number: Represents numeric values, including integers and floating-point numbers. Example: 42, 3.14.
  2. String: Represents a sequence of characters, enclosed in single (' ') or double (" ") quotes. Example: "Hello, World".
  3. Boolean: Represents a binary value, which can be either true or false. Used for logical comparisons and conditional statements.
  4. Undefined: Indicates a variable that has been declared but not assigned a value yet. It also represents the return value of a function with no explicit return statement.
  5. Null: Represents the absence of any object value or no value at all. It is often used to explicitly indicate the absence of an object.
  6. Symbol (ES6): A unique and immutable data type that is often used as property keys in objects.
  7. BigInt (ES11): Allows you to work with large integers beyond the safe range of the Number type.

Reference Data Types:

  1. Object: The most complex data type in JavaScript. It is a collection of key-value pairs, where keys are strings (or Symbols) and values can be of any data type. Objects can represent various data structures, including arrays, functions, and custom-defined objects.
  2. Array: A specialized type of object that stores a list of values, which can be of any data type. Arrays are numerically indexed, and you can use various methods to manipulate their contents.
  3. Function: A reference data type that defines a reusable block of code. Functions are used for tasks such as performing operations, defining behavior, and organizing code into modular units.
  4. Date: Represents dates and times, allowing you to work with and manipulate dates, times, and time zones.
  5. RegExp: Represents regular expressions, which are used for pattern matching within strings.
  6. Map and Set (ES6): Specialized data structures for storing collections of data. Map stores key-value pairs, and Set stores unique values.

These data types provide the building blocks for JavaScript applications. Understanding their characteristics and how to work with them is fundamental to programming in JavaScript.

What are Array operations in JS

In JavaScript, array operations refer to various actions and methods that can be performed on arrays. Arrays are one of the most commonly used data structures in JavaScript, and they provide a way to store and manipulate collections of data. Here are some common array operations in JavaScript:

Adding Elements: push() and unshift()

You can add elements to an array using methods like push(), unshift(), or by directly assigning a value to a specific index.

let fruits = ["apple", "banana"];
fruits.push("cherry"); // ["apple", "banana", "cherry"]
fruits.unshift("orange"); // ["orange", "apple", "banana", "cherry"]
fruits[3] = "grape"; // ["orange", "apple", "banana", "grape"]

Removing Elements: pop() and shift()

You can remove elements from an array using methods like pop(), shift(), or by assigning undefined to a specific index.

let fruits = ["orange", "apple", "banana", "grape"];
fruits.pop(); // ["orange", "apple", "banana"]
fruits.shift(); // ["apple", "banana"]
fruits[1] = undefined; // ["apple", undefined]