Javascript Interview Deck 5 Flashcards

1
Q

What is JavaScript?

A

JavaScript is a high-level, interpreted programming language primarily used for client-side web development. It enables interactive web pages and is commonly used in conjunction with HTML and CSS.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the data types in JavaScript?

A

JavaScript has several built-in data types, including:
Primitive types: string, number, boolean, null, undefined, symbol.
Non-primitive types: object (including arrays and functions).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Explain the concept of hoisting in JavaScript.

A

Hoisting is a JavaScript mechanism where variables and function declarations are moved to the top of their containing scope during compilation, regardless of where they are declared.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the difference between == and === in JavaScript?

A

== is used for loose equality comparison, where type conversion is performed, while === is used for strict equality comparison, where both value and type must be the same.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Explain the event bubbling and event capturing in JavaScript.

A

Event bubbling is a propagation mechanism in the DOM where events are first captured by the innermost element and then propagated to outer elements. Event capturing is the reverse, where events are captured at the outermost element and then propagated to inner elements.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are closures in JavaScript?

A

Closures are functions that have access to the outer (enclosing) function’s variables, even after the outer function has finished executing. They “remember” the environment in which they were created.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are promises in JavaScript?

A

Promises are a way to handle asynchronous operations in JavaScript. They represent a value that may be available now, or in the future, or never. Promises allow chaining asynchronous operations and handling success or failure with then() and catch() methods.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are arrow functions in JavaScript?

A

Arrow functions are a concise way to write anonymous functions in JavaScript. They have a shorter syntax compared to traditional function expressions and do not bind their own this, arguments, super, or new.target.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the difference between let, const, and var?

A

let and const were introduced in ES6 (ECMAScript 2015) for declaring variables. let allows reassignment of the variable’s value, while const does not allow reassignment once a value is assigned. var is the pre-ES6 way of declaring variables and has function scope rather than block scope.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Explain the concept of AJAX.

A

AJAX (Asynchronous JavaScript and XML) is a technique used in web development for creating dynamic web pages that can update content without reloading the entire page. It involves making asynchronous requests to the server using JavaScript and handling the server’s response dynamically.

`

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Explain closures in JavaScript.

A

Closures are inner functions that have access to the outer (enclosing) function’s variables. They “remember” the environment in which they were created, even after the outer function has finished executing. Closures are commonly used for data encapsulation and maintaining state in JavaScript.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is hoisting in JavaScript?

A

Hoisting is a JavaScript mechanism where variables and function declarations are moved to the top of their containing scope during compilation. This allows variables and functions to be used before they are declared. However, only the declarations are hoisted, not the initializations.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the event loop in JavaScript?

A

The event loop is the mechanism in JavaScript responsible for handling asynchronous operations. It continuously checks the call stack for any function that needs to be executed and the callback queue for any asynchronous tasks. It ensures that the call stack is never blocked, allowing non-blocking asynchronous behavior in JavaScript.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How can you handle errors in JavaScript?

A

Errors in JavaScript can be handled using try-catch blocks. Code that may throw an error is placed within the try block, and if an error occurs, it is caught in the catch block. This allows graceful error handling and prevents the script from crashing.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Explain the concept of callback functions.

A

Callback functions are functions that are passed as arguments to other functions and are executed after a specific task is completed. They are commonly used in asynchronous programming to handle asynchronous operations such as AJAX requests, event handling, and timeouts.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the DOM (Document Object Model)?

A

The DOM is a programming interface for web documents. It represents the structure of HTML documents as a tree-like structure, where each node represents an element. JavaScript can manipulate the DOM to dynamically change the content, structure, and style of web pages.

17
Q

What is the purpose of the setTimeout function?

A

The setTimeout function is used to execute a function after a specified delay (in milliseconds). It allows for asynchronous execution of code and can be used for tasks such as animations, delays, and scheduling.

18
Q

How does the “EventEmitter” class work in Node.js?

A

The EventEmitter class in Node.js allows objects to emit named events and register listener functions that will be called when the event is emitted. It facilitates building asynchronous, event-driven applications in Node.js by providing a way to handle events in a non-blocking manner.

19
Q

What is the DOM (Document Object Model)?

A

The Document Object Model (DOM) is a programming interface for web documents. It represents the structure of HTML or XML documents as a tree-like structure, where each node corresponds to a part of the document, such as elements, attributes, and text. The DOM provides a way for programs (usually JavaScript) to interact with and manipulate the content, structure, and style of web pages dynamically.

20
Q

What is the purpose of the setTimeout function?

A

The setTimeout function in JavaScript is used to execute a specified function or piece of code after a specified delay (in milliseconds). It allows for the asynchronous execution of code, enabling tasks like animations, delays, and scheduling. setTimeout is commonly used in scenarios where a certain action needs to be performed after a specific period of time.

21
Q

Explain the difference between null and undefined.

A

Null and undefined are both primitive values in JavaScript that represent the absence of a value, but they have different use cases.
Null is explicitly assigned by developers to represent the absence of any value or as a placeholder for an intentionally missing value.
Undefined typically represents a variable that has been declared but not yet assigned a value. It is also the default value of uninitialized variables and the return value of functions that do not explicitly return anything.

22
Q

How does prototypal inheritance work in JavaScript?

A

Prototypal inheritance is a fundamental feature of JavaScript’s object-oriented programming paradigm. In JavaScript, objects can inherit properties and methods from other objects through their prototype chain. Each object has an internal reference to another object called its prototype. When a property or method is accessed on an object, JavaScript looks for it first on the object itself and then up the prototype chain until it finds a match.

23
Q

Explain event delegation in JavaScript and its benefits.

A

Event delegation is a technique in JavaScript where a single event listener is attached to a parent element, rather than individual child elements. When an event occurs on a child element, it “bubbles up” to the parent element where the event listener is attached. This allows for dynamic handling of events on elements that are added or removed dynamically, reducing the number of event listeners and improving performance.

24
Q

What is the purpose of the “bind” method in JavaScript?

A

The bind method in JavaScript is used to create a new function with a specified this value and, optionally, pre-defined arguments. It allows for explicit setting of the this context for a function, regardless of how it is called. Bind is commonly used to create new functions with a fixed this value, particularly in event handling, callback functions, and method chaining scenarios.

25
Q

Describe the purpose of the “Proxy” object in JavaScript:

A

The Proxy object in JavaScript allows you to intercept and customize operations performed on objects, such as property access, assignment, function invocation, and more. It provides a way to define custom behavior for fundamental operations, enabling features like validation, logging, memoization, and more.`

26
Q

Discuss the concept of prototypal inheritance in JavaScript:

A

Prototypal inheritance is a fundamental feature of JavaScript where objects can inherit properties and methods from other objects through a prototype chain. Each object in JavaScript has an internal reference to another object called its prototype. When a property or method is accessed on an object, JavaScript first looks for it on the object itself and then up the prototype chain until it finds a match.

27
Q

What is the purpose of the “spread” operator in JavaScript?

A

The spread operator (…) in JavaScript is used to expand elements of an iterable (like an array or string) into individual elements. It is commonly used in array literals, function calls, and object literals to spread elements or properties. The spread operator facilitates tasks like concatenating arrays, copying arrays, passing multiple arguments to functions, and more.

28
Q

What is the event loop in JavaScript, and how does it work?

A

The event loop is a mechanism in JavaScript responsible for handling asynchronous operations and ensuring non-blocking behavior. It continuously checks the call stack for functions to execute and the callback queue for tasks to be processed. The event loop prioritizes tasks in the callback queue, allowing JavaScript to handle multiple asynchronous operations concurrently without blocking the main thread.

29
Q

What is the purpose of the “Symbol” data type in JavaScript?

A

The Symbol data type in JavaScript is a primitive value used to create unique identifiers that are guaranteed to be unique across different objects. Symbols are often used as property keys in objects to create private or non-enumerable properties, avoiding naming collisions and unintentional property overriding.

30
Q

What is the purpose of the “use strict” directive in JavaScript?

A

The “use strict” directive is a pragma introduced in ECMAScript 5 (ES5) that enables strict mode in JavaScript code. Strict mode enhances JavaScript by enforcing stricter rules and generating errors for common mistakes and unsafe actions. It helps to catch and fix errors early, improve performance, and make code more secure and maintainable.

31
Q

Discuss the concept of the “async/await” feature in JavaScript:

A

The async/await feature in JavaScript is a syntax introduced in ECMAScript 2017 (ES8) for handling asynchronous code in a more synchronous and readable manner. It allows functions to pause execution until asynchronous operations are completed, using the async keyword to mark a function as asynchronous and the await keyword to pause execution until a Promise is resolved.

32
Q

Explain the concept of closures and provide a practical example:

A

Closures in JavaScript refer to the ability of inner functions to access variables and parameters from their outer (enclosing) function’s scope even after the outer function has finished executing. Closures allow for data encapsulation and maintaining state across function calls. Here’s a practical example:
javascript
Copy code
function outerFunction() {
let outerVariable = ‘Hello’;

function innerFunction() {
    console.log(outerVariable); // Accessing outerVariable from the outer function's scope
}

return innerFunction; }

const innerFunc = outerFunction();
innerFunc(); // Output: Hello

33
Q
A