letis a block-scoped variable, which means it is only accessible within the block it is defined in.
varis a function-scoped variable, which means it is accessible within the entire function in which it is defined.
- A closure is a function that has access to variables in its outer scope, even after the outer function has returned.
- Event bubbling means that when an event is triggered on a child element, it bubbles up to its parent element and triggers the same event on that element. Event capturing is the opposite process, where the event is first captured by the outermost element and then propagates down to the innermost element.
==is a loose comparison, meaning it compares the values of the operands without considering their type.
===is a strict comparison, meaning it compares the values and the types of the operands.
- Can you explain how the
thiskeyword refers to the object that the function is a method of. In other words, it refers to the object on which the function is invoked. Its value is determined by the way the function is called.
undefinedis a value that a variable can be assigned when it has been declared but has not been assigned a value.
nullis a value that is explicitly assigned to a variable to represent no value.
forEachloop is used to iterate over an array and perform a specific operation on each element of the array. A
mapfunction is also used to iterate over an array, but it creates a new array as a result, with each element transformed according to the operation specified in the function.
- By using browser’s developer tools, setting breakpoints, stepping through the code, adding console.logs, using
debuggerstatement, or using frameworks and libraries like React developer tools, Vue devtools, and lots more.
- Synchronous code is code that runs one statement at a time, in the order that it appears in the code. Asynchronous code is code that runs in a non-blocking manner, allowing other code to run at the same time.
try-catchstatement for handling errors. The
tryblock contains the code that may throw an error, and the
catchblock contains the code that will handle the error.
classkeyword to define a class and the
extendskeyword to inherit properties from a parent class.
importkeywords to create and use modules.
- A debounce function is used to limit the rate at which a function can be called. A simple way to implement a debounce function is to use
setTimeout()to call the function after a certain amount of time has passed.
- Lazy loading is a technique for loading content only when it is needed. This can be implemented by using
- How would you explain the difference between call, apply, and bind?
apply()are used to invoke a function with a specific
thisvalue and arguments, while
bind()returns a new function with the
thisvalue and arguments bound to it.
- How would you explain the difference between let and const?
letis used for variables whose values will be reassigned and it is block scoped ,
constis used for variables that are assigned to a value once and cannot be reassigned, it is also block scoped.
- A pure function is a function that does not depend on and does not modify the state of variables outside of its scope and always returns the same output for the same input. Pure functions are important because they are predictable, easy to test and maintain and also helps with functional programing.
=>syntax instead of the
functionkeyword. Arrow functions do not have their own
thiskeyword, they inherit the
thisvalue of the scope in which they are defined. This makes them useful for working with
thisin callback functions, and also it’s a good practice for functional programming.