JavaScript key questions

person shubham sharmafolder_openJAVASCRIPTlocal_offeraccess_time October 16, 2024

Hoisting in JavaScript

Definition: JavaScript moves variable and function declarations to the top of their scope during compilation — this is called hoisting.

Note: Variables declared with let and const are not accessible before initialization (Temporal Dead Zone).

Var, Let, and Const

Summary: These keywords define variables, but differ in scope and re-assignment rules.

  • var — function-scoped, can be re-declared.
  • let — block-scoped, can be reassigned but not re-declared.
  • const — block-scoped and cannot be reassigned.

Temporal Dead Zone (TDZ)

The period between variable creation and initialization when it can’t be accessed. Accessing a let or const variable before initialization throws a ReferenceError.

Lexical Scope

Definition: A function can access variables defined in its outer scope. JavaScript uses lexical scoping based on where functions are written, not where they are called.

Higher-Order Functions

Functions that take other functions as arguments or return them as results.

Shallow Copy vs Deep Copy

Shallow copy copies only references to nested objects, while deep copy creates new independent copies.

Types of Functions

Function Declaration

Function Expression

Anonymous Function

A function without a name, often used as a callback.

Named Function Expression

Useful for recursion or debugging.

Arrow Functions

Shorter syntax and lexical this binding.

Currying

Transforms a function with multiple arguments into nested single-argument functions.

Template Literals

Allow embedded expressions using backticks (`).

Closure

A closure is a function bundled with its lexical environment — it remembers variables from its outer scope even after the outer function has finished.

Spread Syntax & Destructuring

Spread: Expands elements of an array or object.

Destructuring: Extracts values into variables.

Map vs forEach / Find vs Filter

  • map() returns a new array.
  • forEach() executes for side effects, returns undefined.
  • find() returns the first match.
  • filter() returns all matches.

Exception Handling

Use try...catch to handle runtime errors gracefully.

Event Loop

The Event Loop handles asynchronous callbacks, ensuring non-blocking execution.

Promises, Async & Await

Used for asynchronous code flow control.

TypeScript

A superset of JavaScript adding static types, interfaces, and tooling support for safer, scalable code.

Object-Oriented Programming (OOP)

Organizes code into objects with properties and methods. JavaScript supports classes and prototypes.

Threads in JavaScript

  • Execution Thread: The main thread runs all JS code.
  • Worker Thread: Runs scripts in background without blocking the main thread.
  • Cluster: A group of worker processes that share load across CPU cores.

Written by Shubham Sharma — last updated Oct 2025. Visit newdevpoint.in for more tutorials.

Link

React-Native key questions

warningComments are closed.