Basic Interview Questions

What are the data types in JavaScript?

Seven primitives: string, number, bigint, boolean, undefined, null, symbol, and one non-primitive: object (which includes arrays, functions, dates, maps...). Primitives are immutable and copied by value; objects are copied by reference.

Difference between var, let and const?

varletconst
Scopefunctionblockblock
Reassignyesyesno
Redeclareyesnono
Hoistinginitialised as undefinedTDZ until declaredTDZ until declared

Difference between == and ===?

=== compares value and type without conversion. == converts operands to a common type first, e.g. "5" == 5 is true and 0 == "" is true. Use ===.

null vs undefined?

undefined means a value was never assigned (missing property, missing argument, function without return). null is assigned on purpose to mean "no value". typeof null is "object" due to a historical bug; null == undefined is true but null === undefined is false.

What is hoisting?

Before code runs, declarations are registered at the top of their scope. Function declarations are fully hoisted (callable before their line); var is hoisted as undefined; let/const/class are hoisted but in the temporal dead zone until declared.

What are arrow functions and how do they differ from normal functions?

  • Shorter syntax with implicit return for one expression.
  • No own this, arguments or super: they use the surrounding ones.
  • Cannot be used as constructors with new.
  • Good for callbacks; not for object methods that need this.