- What is JavaScript?
- JavaScript is a high-level, interpreted scripting language that enables interactive web pages. It is part of the core trio of web technologies, alongside HTML and CSS.
- What is the difference between
==
and===
in JavaScript?==
is the loose equality operator that compares values for equality after performing type coercion if necessary.===
is the strict equality operator that compares both the value and type, without performing type coercion.
- What is a closure in JavaScript?
- A closure is a function that has access to the parent scope’s variables, even after the parent function has closed.
- How does JavaScript handle asynchronous operations?
- JavaScript handles async operations through mechanisms like callbacks, promises, and async/await. The event loop, Web APIs (in the browser), and the task queue allow JS to perform non-blocking operations.
- What is the difference between
var
,let
, andconst
in JavaScript?var
is function-scoped and was the way to declare variables in ES5.let
andconst
are block-scoped. Whilelet
allows variable reassignment,const
does not.
- What is hoisting in JavaScript?
- Hoisting is JavaScript’s behavior of moving variable and function declarations to the top of their containing scope. However, only the declarations are hoisted; initializations are not.
- How do you differentiate between
null
andundefined
?- Both represent “no value” or “absence of a value.” However,
undefined
typically means a variable has been declared but not assigned a value.null
is a value that represents no value or no object.
- Both represent “no value” or “absence of a value.” However,
- What is the prototype chain or prototype inheritance in JavaScript?
- JavaScript objects have a link to another object called its prototype. When trying to access a property of an object, it first checks the object itself. If not found, it looks in the object’s prototype, then the prototype’s prototype, and so on, forming the prototype chain.
- What are arrow functions, and how are they different from regular functions?
- Introduced in ES6, arrow functions allow for a shorter syntax when writing functions. They also lexically bind the
this
value, meaning they don’t create their ownthis
context, making them handy for certain scenarios.
- Introduced in ES6, arrow functions allow for a shorter syntax when writing functions. They also lexically bind the
- What is the
this
keyword in JavaScript?
this
is a special keyword that refers to the context in which a function was invoked. Its value can be different based on how a function is called (e.g., as a method, as a constructor, withcall
/apply
, or as a regular function).
Like with the React and JS questions, these answers are concise overviews. The depth of explanations and follow-ups can vary based on context and the expertise of the individual asking.