JS/TS Interview Questions

Created
Aug 22, 2024 11:35 AM
Tags

ECMAScript

Foundation of JS. Created by Brenden Eich in 1997.

Language Characteristics

  • Multi-paradigm: ECMAScript supports multiple programming paradigms, including object-oriented, imperative, and functional programming styles.
  • Dynamic Typing: The language is dynamically typed, meaning that variable types are determined at runtime rather than at compile time.
  • Core Features: ECMAScript includes built-in objects (like Array and Function), operators, and a set of syntactic rules that resemble those of Java, making it accessible for developers familiar with traditional programming languages

ES Versions

Version
Release Year
Key Features
ES1
1997
Initial version
ES2
1998
Editorial changes only
ES3
1999
Regular expressions, try/catch
ES4
Abandoned
Major overhaul, never released
ES5
2009
Strict mode, JSON support, Array.prototype methods
ES6 (ES2015)
2015
Classes, modules, let/const, arrow functions, promises, destructuring, generators, proxies, symbols
ES7 (ES2016)
2016
Exponentiation operator (**), Array.prototype.includes
ES8 (ES2017)
2017
Async/await, Object.values, Object.entries, Object.getOwnPropertyDescriptors
ES9 (ES2018)
2018
Asynchronous iteration, Promise.prototype.finally, rest/spread properties, RegExp named capture groups
ES10 (ES2019)
2019
Array.prototype.{flat,flatMap}, Object.fromEntries, trimStart, trimEnd
ES11 (ES2020)
2020
BigInt, Promise.allSettled, globalThis, dynamic imports, matchAll
ES12 (ES2021)
2021
Promise.any, replaceAll, logical assignment operators, numeric separators
ES13 (ES2022)
2022
at method for arrays and strings, error cause, Symbol.for registry
ES14 (ES2023)
2023
Top-level await, error cause, Array.prototype.findLast, Object.hasOwn
ES15 (ES2024)
2024
Object.groupBy, Map.groupBy, Promise.withResolvers, /v regex flag

Data Types in JS

JavaScript has six primitive data types:
  • Number
  • String
  • Boolean
  • Null
  • Undefined
  • Symbol
It also has two compound data types:
  • Object
  • Array

What is hoisting in JavaScript?

Hoisting is a JavaScript concept that refers to the process of moving declarations to the top of their scope. This means that variables and functions can be used before they are declared, as long as they are declared before they are used in a function.
For example, the following code will print "Hello, world!" even though the greeting variable is not declared until after the console.log() statement.
Variable Hoisting
console.log(x); // Output: undefined var x = 5;
The code above is interpreted by the JavaScript engine as:
var x; console.log(x); // Output: undefined x = 5;
Function Hoisting
Function declarations are also hoisted to the top of their respective scopes. This allows you to call a function before it is declared in your code.
greet(); // Output: "Hello!" function greet() { console.log("Hello!"); }
However, function expressions are not hoisted. Only the variable declaration is hoisted, not the assignment.
greet(); // TypeError: greet is not a function var greet = function() { console.log("Hello!"); };
The code above is interpreted as:
var greet; greet(); // TypeError: greet is not a function greet = function() { console.log("Hello!"); };

What is the difference between null and undefined?

null is an assignment value that represents no value or an empty value, while undefined is a variable that has been declared but not assigned a value.
notion image

What is the difference between == and === operators in JavaScript?

The equality == operator is a comparison operator that compares two values and returns true if they are equal. The strict equality === operator is also a comparison operator, but it compares two values and returns true only if they are equal and of the same type.
For example, the following code will return true, because the values of the x and y variables are equal.
notion image