JS Flashcards

1
Q

Difference between let and var

A

let has block scope, var has function scope.

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

Arrow functions vs regular functions

A

arrow functions do not have their own this.

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

== vs ===

A

== only checks value equality and === checks type and value

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

What is ASI?

A

Automatic semicolon insertion

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

What are all primitive data types?

A

Value types:
- Number
- String
- Boolean
- BigInt
- Null
- Undefined
- symbol
Are immutable, create a new copy when operation to modify is performed.

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

What are non-primitive data types?

A

Reference types:
- Object
- Array
- Functions
- Date
- Custom objects
- RegExp
Any changes made to an object/array modifies the original object.

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

What is typeof used for?

A

It is used to return a string with the type of an unevaluated operand (object or primitive).

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

What is instanceof used for?

A

It returns true if an object is an instance of an object type.

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

What is the void expression?

A

Evaluates a given expression and returns undefined. Used to return a primitive value as undefined.
let myVar = void 10; // returns undefined

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

Difference between break and continue statements

A

Break:
- It is used to jump out of switch statements or loops.
- With a label reference, the break statement can be used to jump out of any code block.

Continue:
- breaks an interaction if a certain condition occurs then continues with the next iteration.

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

What is short-circuiting?

A

It is a conditional evaluation in which an operand may not be evaluated at all.

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

For … of …

A

Used to iterate over the values stored in an iterable data structure, such as array, set, or map. It contains the value of the element that corresponds with the current iteration of the loop. The variable initialized at the start of each iteration, and removed at the end of that iteration.

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

For … in …

A

Used to iterate over the enumerable properties of an object, including enumerable inherited properties.

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

push/shift/pop

A
  • push = adds element to the end
  • pop = takes element from the end
  • shift = gets an element from the beginning advancing the queue (2nd element becomes 1st)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

User interactions (alert, prompt, confirm)

A
  • alert = shows a message and waits for the user to press ok
  • prompt = shows modal window with a text message, an input field for the visitor and the buttons ok/cancel
  • confirm = shows modal window with a question and buttons ok/cancel
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How is the spread operator used?

A

let a = [1, -2, 4, 0];
console.log(Math.min(…a)); ===> -2