JAVASCRIPT Flashcards

1
Q

What are the different data types in JavaScript?

A

8 of them : String, number, boolean, BigInt, un defined, null, symbol and object

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

Explain hoisting in JavaScript.

A

Hoisting is the default behaviour of javascript where all the variable and function declarations are moved on top.

This means that irrespective of where the variables and functions are declared, they are moved on top of the scope. The scope can be both local and global.

To avoid hoisting, you can run javascript in strict mode by using “use strict” on top of the code:

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

Difference between “ == “ and “ === “ operators.

A

Both are comparison operators.
“==” is used to compare values, “ === “ is used to compare both values and types.

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

What is NaN property in JavaScript?

A

NaN property represents the “Not-a-Number” value. It indicates a value that is not a legal number.

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

What is the difference between ‘undefined’ and ‘null’ in JavaScript?

A

undefined means a variable has been declared but has not yet been assigned a value.

null is an assignment value. It can be assigned to a variable as a representation of no value :

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

How would you handle errors in JavaScript?

A

Errors in JavaScript can be handled using try-catch blocks, where code that may throw an error is placed within the try block, and the catch block handles the error if it occurs.

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

How does asynchronous programming work in JavaScript? Explain callbacks or Promises.

A

Asynchronous programming in JavaScript allows tasks to run in the background. Callbacks and Promises are two ways to handle asynchronous code. Callbacks are functions passed as arguments and executed when the task is complete. Promises represent the eventual completion or failure of an asynchronous operation, providing a structured approach to handle it.

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

What is a closure in JavaScript?

A
  • A closure is a function that has access to variables in its outer function, even after the outer function has returned.
  • It is created by nesting a function inside another function and returning the inner function.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is event delegation in JavaScript?

A

Event delegation is a technique in JavaScript where instead of attaching event listeners to individual elements, you attach a single event listener to a parent element. The events are then handled when they bubble up from the child elements. This approach is useful for dynamically created elements or when dealing with a large number of elements.

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

What are the higher order functions in JavaScript?

A
  • Higher order functions are functions that take one or more functions as arguments or return a function as their result.
  • They are a key feature of functional programming in JavaScript.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

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

A
  • let and const are block-scoped, while var is function-scoped.
  • The value of a variable declared with const cannot be reassigned, while the value of a variable declared with let or var can.
  • Variables declared with let and const are not hoisted, while variables declared with var are hoisted.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the difference between synchronous and asynchronous programming in JavaScript?

A
  • Synchronous programming executes code sequentially, one line at a time.
  • Asynchronous programming allows code to be executed out of order, and it usually involves the use of callbacks, promises, or async/await.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is JavaScript?

A
  • JavaScript is a programming language that is used to create interactive effects within web browsers.
  • It is a high-level, interpreted language that is easy to learn and use.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the event loop in JavaScript?

A
  • The event loop is a mechanism in JavaScript that allows for asynchronous programming.
  • It continuously checks the call stack and the message queue to see if there are any tasks that need to be executed.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly