JavaScript Flashcards

1
Q

What is Scope?

A

Refers to the availability of variables in our code

or

Scope dictates where JS engine should look for things

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

What is the scope of Var?

A

function scoped

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

What is the scope of let and const ?

A

block scoped

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

How are var declarations hoisted?

A

var declarations when hoisted they are initialized with undefined.

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

How are let and cont declarations hoisted?

A

when hoisted they are not initialized with undefined.

So, this would trigger a reference error if accessing before declaration.

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

What is Hoisting?

A

Hoisting means moving variable declarations to the top of their scope.

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

What are your use cases for variable declarations?

A

Try to use const declarations

If the value is expected to change, use let declaration

var declarations can be avoided as they introduce unnecessary confusion

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

Can you redeclare variables with the let keyword

A

No, this is not possible.

Error: Syntax Error: Identifier ‘name’ has already been declared

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

Does a function have access to global scope?

A

Yes, a function will always have access to its own function scope as well as the global scope.

A function can access variables defined with in the function as well as outside the function

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

What is Lexical Scoping?

A

means that a variable defined outside a function can be accessible inside another function defined after the variable declaration. But the opposite is not true; the variables defined inside a function will not be accessible outside that function.

‘this’ refers to it’s current surrounding scope and no further.

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

What is Scope Chain?

A

When we have nested functions, the JS engine for variable lookup starts with the inner most function where we are trying to access the variable and moves outward until it reaches the global scope

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

What is important to remember about Scope and nested functions?

A

Nested function have access to variables declared in their own scope as well as variables declared in the outer scope

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

What are Closures?

A

A closure is the combination of a function bundled together (enclosed) with references to its surrounding state (the lexical environment).

In JavaScript, closures are created every time a function is created, at function creation time.

Further info:
This would let the function definition have an associated persistent memory which could hold on to live data between executions

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

What is Memoization

A

An optimization technique used primarily to speed up computer programs by storing the results of expensive function calls and returning the cached results when the same inputs occur again

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

What is Function Currying?

A

Currying is a process in functional programming in which we transform a function with multiple arguments into a sequence of nesting functions that take one argument at a time

function fn(a,b,c) transformed into fn(a)(b)(c)

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

What is ‘this’?

A

The JavaScript this keyword refers to the object it belongs to. You can set it with bind() among others.

‘this’ keyword is the execution context for a function call

It allows you to introduce reusability by allowing this value to be dynamic based on how a function is invoked

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

What is default binding

A

If call, apply, bind are not set, JS will default to the global scope and set ‘this’ keyword to the window object.

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

What are the five ways to invoke a function?

A

Implicit binding, Explicit binding, ‘new’ binding, default binding and Lexical Binding

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

Using implicit Binding, how do we know what ‘this’ is referencing?

A

When the function in invoked with the dot notation, the object to the left if that dot is what the this keyword is referencing.

Ex. person.sayMyName( )
‘this’ keyword is referencing the ‘person’ object

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

What is the first num called?

function myFunc(num){
    return num
}
myFunc(2)
A

Parameter

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

What is 2 called?

function myFunc(num){
    return num
}
myFunc(2)
A

Argument

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

What is the difference between call and bind methods

A

instead of invoking the function, Bind returns a new function that you can invoke whenever you wish

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

What do you know about arrow functions?

A

Introduced in ES6
Concise Function syntax
Provides Lexical binding
Can’t be called with new keyword

Arrow functions do not bind their own “this” , instead, they inherit the one from the parent scope, which is called “lexical scoping”

24
Q

What are Higher Order Functions?

A

This is a function that can take in another function

Ex. The .map() function is a higher order function that will run a callback on every item in the array and will push each result into a new array.

25
Q

What are first class functions?

A

function that was built with the intention of being passed around to other functions. It does one specific thing, does not have side effects, and is not intended to be called directly, but rather, to be used by ‘other functions.’

26
Q

What is Functional programming?

A

is the process of building software by composing pure functions, avoiding shared state, mutable data, and side-effects. Functional programming is declarative rather than imperative, and application state flows through pure functions.

27
Q

What are Callbacks?

A

is a function passed into another function as an argument to be executed later.

28
Q

What does the new keyword do?

A
  • creates a new empty object { }
  • sets the value of ‘this’ to be the new empty object
  • calls the constructor method

In constructor, new keyword moves the this keyword from global object to inside the object

https://www.youtube.com/watch?v=HboT8g_QSGc

29
Q

T or F does every Object have a Prototype property?

A

True

30
Q

What is a promise

A

A promise is an object that may produce a single value some time in the future : either a resolved value, or a reason that it’s not resolved

31
Q

What are the differences between == and === ?

A

a===b means that a and b are equal in both value and type.

a==b means that they are equal in value only.

32
Q

Why use SASS?

A

SASS gives you access to variables and functions in CSS. Also it has a compiler that helps with debugging and you can nest classes.

33
Q

What is the difference between null and undefined.

A
Undefined means a variable has been initialized but not been assigned a value; 
  //var initialized 
   let a;
  //this log will give undefined
   console.log(a) 

null is an assignment

//var initialized and assigned to null 
let a = null; 
//log will give null 
console.log(a)
34
Q

What is 403 error

A

The 403 status code, or a Forbidden error, means that the user made a valid request but the server is refusing to serve the request, due to a lack of permission to access the requested resource.

35
Q

What is the virtual DOM?

A

A virtual DOM is a lightweight JavaScript representation of the DOM used in declarative web frameworks such as React, Vue.js, and Elm. Updating the virtual DOM is comparatively faster than updating the actual DOM, since nothing has to be rendered onto the screen.

36
Q

What is deconstructing

A

Add Answer here

37
Q

What is a class

A

Add Answer here

38
Q

What is UseEffect

A

React Hook

Fires a function with the component first mounts

39
Q

Why do we need react Keys

A

Add Answer here

40
Q

What is the difference between apply and call binding?

A

Apply method accepts arguments in an array

Call method accepts arguments in strings

41
Q

What are unit tests?

A

Testing code or a component in complete isolation

42
Q

What are Integration Tests

A

Test how components work together and if they are working together properly.

43
Q

End to End Testing

A

Simulates what the user is going to do.

Ex. From login to using all the features of the app.

44
Q

What is Jest?

A

the testing library used by React Testing Library

45
Q

A promise is always in one of three states. What are the three states?

A

Pending: which is initial state, neither fulfilled nor rejected

Fulfilled: meaning that the operation completed successfully

Rejected: meaning that the operation failed.

46
Q

Why use Promises?

A

Promises help us deal with asynch code in a far more simpler way compared to callbacks

47
Q

How do you change that status of a promise?

A

Through Resolve and Reject

resolve() - changes status from pending to fulfilled

reject() - changes status from pending to rejected

48
Q

Can you directly mutate the state of a promise?

A

No.

49
Q

What two methods/functions does the Promise Object provide access to?

A

.then() - called with promise.then()

.catch() - called with promise.catch()

50
Q

Can Promises be chained?

A

Yes

51
Q

What is Promise.all()

A

Allows us to query multiple APIs and preform some actions but only after all the APIS have finished loading

If one promise rejects, promise.all() will reject with an error message.

52
Q

What does Promise.allSettled() do?

A

Promise.allSettled() method waits for all input promises to complete regardless of whether or not one of them is rejected

53
Q

What does Promise.race() do?

A

Promise.race() method returns a promise that fulfills or rejects as soon as one of the input promises fulfills or rejects, with the value or reason from that promise.

54
Q

What are Classes?

A

Classes are like a blue print. Ex. Class could be an email for several users.

Every user has a different value for an email and email is the class.

55
Q

What is a constructor function?

A

Creates new objects based upon the Class