Javascript Flashcards

1
Q

What is ECMAScript in JavaScript?

A

ECMAScript (or ES) is the standard specification for JavaScript that defines the core features and syntax of the language. JavaScript is the most popular implementation of ECMAScript.

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 in JavaScript?

A

var declares variables with function scope.
let declares variables with block scope (ES6).
const declares constants with block scope, whose value cannot be reassigned once defined.

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

What is the spread operator, rest operator, and default parameter in JavaScript?

A

Spread (…) operator: Used to expand iterable objects into multiple elements.
Rest (…) parameter: Collects multiple arguments into an array.
Default parameter: Allows function parameters to have default values if not provided.

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

What is deep copy and shallow copy in JavaScript?

A

Deep copy: Creates a copy of nested objects and their values recursively.
Shallow copy: Copies the top-level structure of objects, with references to nested objects (not deeply cloned).

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

What are promises, callback functions, async/await in JavaScript?

A

Promises: Objects representing the eventual completion (or failure) of an asynchronous operation.
Callback functions: Functions passed as arguments to another function, to be executed later.
async/await: Asynchronous JavaScript feature that simplifies writing asynchronous code using promises.

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

What is the difference between a promise and a callback in JavaScript?

A

Promises provide a cleaner way to handle asynchronous operations compared to nested callbacks, offering better error handling and sequential chaining.

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

What is event bubbling and event capturing in JavaScript?

A

Event bubbling: When an event occurs on a nested element, it triggers parent elements in the DOM hierarchy.
Event capturing: The opposite process, where events are captured starting from the outermost parent down to the target element.

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

What is a higher-order function in JavaScript?

A

A higher-order function is a function that either takes another function as an argument or returns a function as a result. Examples include map, filter, reduce.

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

Explain different types of functions in JavaScript?

A

JavaScript functions include function declarations, function expressions, arrow functions, and generator functions, each with specific use cases and syntax.

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

What is an arrow function in JavaScript?

A

Arrow functions are concise function syntax introduced in ES6, providing a shorter syntax for writing function expressions. They use a fat arrow (=>) and have implicit return.

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

Why do we use call, apply, and bind methods in JavaScript?

A

call, apply, and bind are methods used to manipulate the context (this value) of a function, allowing explicit setting of this and passing arguments.

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

How many ways to create objects in JavaScript?

A

Objects in JavaScript can be created using object literals, constructor functions (new Object()), classes (ES6), and Object.create() method.

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

What is prototype inheritance in JavaScript?

A

Prototype inheritance is the mechanism where objects inherit properties and methods from a prototype object, forming a prototype chain. It allows objects to share behavior and avoid redundancy.

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

What is TypeScript?

A

TypeScript is a superset of JavaScript that adds static typing, interfaces, and other features for building large-scale applications. It compiles to plain JavaScript.

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

What are array methods and string methods in JavaScript?

A

Array methods (map, filter, reduce, forEach, etc.) and string methods (toUpperCase(), substring(), indexOf(), split(), etc.) provide functionalities to manipulate arrays and strings.

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

What is the difference between Java and JavaScript?

A

Java is a statically typed, object-oriented programming language used for backend development, while JavaScript is a dynamically typed scripting language used for client-side web development.

17
Q

What is throttling and debouncing in JavaScript?

A

Throttling and debouncing are techniques to optimize performance by limiting the frequency of function executions based on time intervals (setTimeout) or event triggers.

18
Q

What are null and undefined in JavaScript?

A

null represents an intentional absence of any object value, while undefined indicates that a variable has been declared but not assigned a value.

19
Q

What are falsy values in JavaScript?

A

Falsy values in JavaScript are false, 0, ‘’ (empty string), null, undefined, and NaN.

20
Q

What is the execution context, event loop, stack, call queue, microtask queue in JavaScript?

A

The execution context manages the scope, variables, and this value of a function during execution. The event loop manages asynchronous operations by processing tasks from the call stack, microtask queue, and callback queue.

21
Q

What are setTimeout and setInterval in JavaScript?

A

setTimeout executes a function after a specified delay, while setInterval repeatedly executes a function at specified intervals until stopped.

22
Q

What are Object.seal and Object.freeze in JavaScript?

A

Object.seal seals an object, preventing new properties from being added and existing properties from being removed. Object.freeze freezes an object, making it immutable (properties cannot be changed, added, or removed).

23
Q

What is the difference between Map and Set in JavaScript?

A

Map is a collection of key-value pairs allowing keys of any type, while Set is a collection of unique values with no duplicate entries.

24
Q

What are WeakMap and WeakSet in JavaScript?

A

WeakMap and WeakSet are collections that hold weak references to their keys, allowing those keys to be garbage-collected if no other references exist.

25
Q

What are sessionStorage, localStorage, and cookies in JavaScript?

A

sessionStorage and localStorage are web storage APIs for storing data on the client-side, with localStorage persisting data beyond sessions. Cookies are small text files stored by websites on a user’s device.

26
Q

Write a program to sort an array in JavaScript.

A

Example: const numbers = [3, 1, 2]; numbers.sort((a, b) => a - b); console.log(numbers); (Sorts the array numbers in ascending order).

27
Q

What is the use of JSON.stringify and JSON.parse() methods in JavaScript?

A

JSON.stringify converts JavaScript objects into JSON strings, while JSON.parse() parses JSON strings back into JavaScript objects.

28
Q

What are map, filter, and reduce in JavaScript?

A

map: Creates a new array by applying a function to each element.
filter: Creates a new array with elements that pass a test.
reduce: Reduces an array to a single value by applying a function.

29
Q

hat is a generator function in JavaScript?

A

A generator function (function*) is a special type of function that can pause execution (yield keyword