As I have been recently impacted by my previous company’s layoff, I have had to start re-learning how to interview prep. I started a Github repo to gather my resources and I thought it would reach a wider audience if I were to post on Medium as well.
What is event delegation?
Describe event bubbling
Explain how prototypal inheritance works
What is the difference between a variable that is:
null, undefined or undeclared?
undeclared: It refers to a variable that has been referenced without being declared using the
const keyword. It results in a ReferenceError when trying to access an undeclared variable.
null is an assigned value indicating the absence of an object,
undefined is the default value for uninitialized variables, and
undeclared variables are those that have not been declared at all.
What is a closure, and how/why would you use one?
A closure is a combination of a function and the lexical environment in which it was declared. It allows a function to access variables from its outer scope even after the function has finished executing. Closures are useful for creating private variables, encapsulation, maintaining state, and handling callbacks and asynchronous operations effectively.
Can you describe the main difference between the
Array.forEach() loop and
Array.map() methods and why you would pick one versus the other?
The main difference between
Array.map() methods is in their return values and the purpose they serve.
Array.forEach() is used when you want to iterate over each item in an array and perform some action or operation on it. It does not return a new array; instead, it executes a callback function for each item in the array.
Array.map(), on the other hand, is used when you want to transform each item in an array and create a new array based on the transformation. It returns a new array by applying a callback function to each item in the original array.
What is a typical use case for anonymous functions?
A typical use case for anonymous functions is when you need a function for a specific task that doesn’t require reusability or naming. Anonymous functions are commonly used in scenarios such as: callback functions, immediately invoked function expressions, event handlers, and function arguments.
What is the difference between host objects and native objects?
Can you explain what
Function.call: It invokes a function by specifying the
this value and passing arguments individually. The first argument of call is the value to be assigned to this, followed by the individual arguments to be passed to the function.
Function.apply: It invokes a function by specifying the
this value and passing arguments as an array or an array-like object. The first argument of
apply is the value to be assigned to this, and the second argument is an array or array-like object containing the arguments to be passed to the function.
The notable difference between
apply lies in how the arguments are passed to the function. With
call, the arguments are passed individually, while with
apply, they are passed as an array or array-like object.
Function.prototype.bind creates a new function with a specified
this value and partially applied arguments, allowing for deferred execution and convenient customization of function invocation.
What is the difference between feature detection, feature inference, and using the UA string?
Feature detection is a reliable technique that directly tests for the presence of specific features, while feature inference makes assumptions based on related features. Using the UA string involves extracting information from the client’s browser and operating system, but it can be less accurate and prone to manipulation.
var and functions declared with the
What is the difference between an “attribute” and a “property”?
Attribute: An attribute is a value specified in HTML markup and defines initial or additional information about an HTML element. It is defined in the HTML source code and accessed using methods like
What is the difference between
== is an equality operator that performs type coercion, allowing comparison between values of different types by converting them to a common type. On the other hand,
=== is a strict equality operator that compares values without type coercion, requiring both the value and the type to be the same for the comparison to be true.
What is strict mode? What are some of the advantages/disadvantages of using it?
Strict mode offers benefits such as improved error handling, cleaner code, enhanced security, and future compatibility. However, it can introduce compatibility issues with older environments and may require adjustments to existing code.
Explain the difference between mutable and immutable objects
Mutable objects: Mutable objects are objects whose states can be changed after they are created. This means that properties and values of mutable objects can be modified, added, or removed throughout the program execution.
Immutable objects: Immutable objects, on the other hand, are objects whose state cannot be changed once they are created. This means that once an immutable object is created, its properties and values remain fixed and cannot be modified.
What are the pros and cons of immutability?
Immutability offers benefits such as predictability, simplified code, thread safety, and potential performance optimizations. However, it can introduce memory overhead, performance impact, and object creation overhead.
Explain the difference between synchronous and asynchronous functions
The key difference between synchronous and asynchronous functions is how they handle the flow of execution. Synchronous functions execute sequentially, while asynchronous functions initiate tasks and continue with other operations without waiting for the task to finish.
What is an event loop? What is the difference between a call stack and a task queue?
The event loop continuously checks the call stack and task queue. It executes tasks from the task queue when the call stack is empty, ensuring the proper handling of asynchronous operations and maintaining the responsiveness of the program. The call stack manages the execution context of synchronous code, while the task queue holds tasks/callbacks associated with asynchronous operations.
What are the differences between variables created using
var has function or global scope, can be redeclared, and is hoisted.
const have block scope, cannot be redeclared within the same scope, and are not hoisted. The difference between
const is that
let allows reassignment of values, while
const variables are constant and cannot be reassigned.
What is the definition of a higher-order function?
A higher-order function is a function that takes one or more functions as arguments or returns a function as its result. It operates on functions, treating them as first-class citizens. Higher-order functions enable powerful functional programming techniques such as function composition, currying, and abstraction of control flow. They provide flexibility and modularity in code by allowing functions to be dynamically created and manipulated.
What is a Promise?
Encapsulation: Use objects to encapsulate related data and behavior together. Group related properties and functions into objects, allowing you to create reusable and modular code.
Inheritance: Utilize prototypal inheritance to create hierarchical relationships between objects. Inherit properties and methods from a parent object to a child object, promoting code reuse and providing a structured way to extend functionality.
Abstraction: Abstract away complex implementation details by exposing a simplified interface. Hide internal implementation details and provide public methods that allow users to interact with objects without needing to understand their internal workings.
Composition: Compose objects by combining smaller, more focused objects to create larger, more complex objects. This promotes code reuse and modularity, allowing you to build systems with interchangeable and interchangeable parts.