JS Fundamentals Flashcards

1
Q

What is the difference between undefined, null and undeclared?

A

Undefined is a value that has been declared but not defined.

Null is an intentional value to convey the absence of a value.

Undeclared is value that has not been declared (using var, let, const, etc.).

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

What is a primitive value?

A

Data that is not an object and has no methods and are immutable.

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

What are the six primitive values?

A
  1. ) String
  2. ) Number
  3. ) BigInt
  4. ) Boolean
  5. ) Undefined
  6. ) Symbol
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Of what type are variables that are NOT primitive?

A

Object

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

What are the two basic groups of data types in JavaScript?

A

Primitive and Reference Types

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

What is hoisting?

A

JavaScript’s default behavior of moving variable declarations, function declarations and class declarations to the top.

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

What’s the difference between declarations and initializations?

A

Declaration: declaring a variable (ex. var text;)

Initialization: initializing a value for a variable (text = “123”)

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

What gets hoisted to the top?

A

Declarations NOT initializations!! Function declarations and NOT function expressions!

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

What value is a variable assigned when declared with “var”?

A

undefined

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

What value is a variable assigned when declared with “const” or “let”?

A

It will not be initialized. It will result in an error

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

Are JavaScript classes hoisted?

A

Yes, only class declarations. They result in same as variables declared with “const” or “let” where they are uninitialized until evaluation. Safer to write a class and then use it.

Class expressions are NOT hoisted!

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

Can an arrow function be used as a constructor function?

A

No. Arrow functions do not have its own “new.target” property so it cannot be used as a constructor function.

It cannot be called by “new” as there is no internal method that allows it.

They also don’t have the “prototype” property.

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

What is “new.target”?

A

A property that lets you detect whether a function or constructor was called using the “new” operator.

In constructors and functions invoked using the new operator, “new.target” returns a reference to the constructor or function.

In normal function calls, “new.target” is undefined.

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

What are the types of scope available in JavaScript?

A

There are two types:

  1. ) Local Scope
  2. ) Global Scope
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What type of scope does JavaScript have?

A

Function scope, where each function creates a new scope.

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

What are local variables in JavaScript?

A

Variables that are only visible in the function where it was defined.

They are created when a function starts and deleted when the function is completed.

17
Q

What are global variables in JavaScript?

A

Variable declared outside a function. Can be accessed by any function.

18
Q

What happens when you assign a value to a variable that hasn’t been declared?

A

It becomes global.

19
Q

What happens when you assign a value to a variable that hasn’t been declared, but you’re running in “strict mode”?

A

The variable does NOT become global.

20
Q

What is the call method?

A

A method that allows you to use one method on different objects.

21
Q

What is the apply method?

A

Like the “call” method, a method that allows you to use one method on different objects.

22
Q

What’s the difference between the .call and .apply methods?

A

They are the same except that the “call” method accepts each parameter to be passed individually whereas the “apply” method accepts an array of parameters as the second parameter. The first parameter is the context of “this”.

23
Q

How do you call the “call” method?

A

{method you want to be shared}.call({context of “this”}, {parameters, delimited by a comma})

24
Q

How do you call the “apply” method?

A

{method you want to be shared}.apply({context of “this”}, [{array of parameters}])

25
Q

What happens when you don’t pass all the arguments needed for a method where you use “call” or “apply”?

A

The rest of the parameters will be undefined.

26
Q

What does the “bind” method do?

A

It creates a new function of the function that it’s being called on and attaches the “this” context to it so that it can be called at a later time.

27
Q

What is a closure?

A

A function that can access the variables of an outer scope.

It’s important to note that an outer function will not have access to an inner scopes’ variables.

28
Q

Why would we use a closure?

A
  1. ) Data Privacy
  2. ) Currying
  3. ) Event Handlers
  4. ) Async Callback Functions
29
Q

Is JavaScript a single or multi-threaded language?

A

Single

30
Q

What is a call stack?

A

A stack that receives line by line of code by the interpreter. As they execute, they pop from the stack (from the back).

31
Q

What is the event table?

A

When the interpreter, while in the process of placing code lines into the call stack, comes across asynchronous code, it places it in the event table.

A table that holds asynchronous code and moves it to an event queue once the allotted time necessary for the code to run happens.

32
Q

What is the event queue?

A

A queue that receives asynchronous code from the event table and is responsible for passing it to the event loop.

33
Q

What is the event loop?

A

Process that continuously checks on the call stack and the event queue.

Makes sure to take code from the event queue (from the front) once the call stack is empty.

34
Q

What is one benefit to using “let” vs “var” in async code and closures?

A

“let” creates a new binding for variables, while “var” keeps the same binding.