JavaScript Flashcards

1
Q

What are the data types in JavaScript?

A

JavaScript has several data types, including Primitive types (String, Number, Boolean, Null, Undefined, Symbol, BigInt) and Reference types (Objects, Arrays, Functions).

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

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

A

var is function-scoped or globally scoped and can be re-declared and updated. let is block-scoped, can be updated but not re-declared, while const is block-scoped, cannot be updated or re-declared, and is used for constants.

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

What is a closure in JavaScript?

A

A closure is a function that retains access to its lexical scope, even when executed outside that scope, commonly used for data encapsulation.

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

Explain the concept of hoisting.

A

Hoisting is JavaScript’s behavior of moving variable and function declarations to the top of their containing scope during the compile phase, allowing references before declarations.

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

What are promises, and how do they work?

A

A promise is an object representing the eventual completion or failure of an asynchronous operation, with three states: pending, fulfilled, or rejected, and handled using .then() and .catch().

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

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

A

== performs type coercion, converting operands to the same type for comparison, while === is a strict equality comparison that checks both value and type without coercion.

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

What is event delegation?

A

Event delegation is a technique where a single event listener is attached to a parent element to manage events for multiple child elements, improving efficiency.

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

What is the difference between null and undefined?

A

null is a deliberate assignment of ‘no value’ to a variable, while undefined indicates a variable that has been declared but not assigned a value.

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

What are arrow functions, and how do they differ from regular functions?

A

Arrow functions provide a shorter syntax for writing functions and do not have their own this, inheriting it from the enclosing lexical context.

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

Explain the concept of the ‘this’ keyword in JavaScript.

A

The this keyword refers to the context in which a function is called, changing its value based on the invocation method (e.g., method call, function call).

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

What are template literals?

A

Template literals are string literals that allow embedded expressions, defined using backticks (``), with placeholders indicated by ${expression}.

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

What is the event loop in JavaScript?

A

The event loop is a mechanism that allows JavaScript to perform non-blocking operations by continuously checking the call stack and message queue, executing functions from the stack and processing queued messages.

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

Explain how map, filter, and reduce work.

A

map creates a new array populated with results from a provided function on every element. filter creates a new array with all elements that pass a test implemented by a provided function. reduce executes a reducer function on each element, resulting in a single output value.

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

What is the purpose of the bind, call, and apply methods?

A

These methods change the this context of a function: call calls a function with a given this value and arguments provided individually; apply calls a function with a given this value and arguments as an array; bind returns a new function permanently bound to a specific this value and initial arguments.

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

What is the difference between synchronous and asynchronous programming?

A

Synchronous: Code is executed sequentially, blocking subsequent code until the current operation completes. Asynchronous: Code can be executed in parallel, allowing other operations to run without waiting for the current operation to finish.

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