Javascript Flashcards

1
Q

WithOUT ES6, how are class properties inherited from the parent?

A

Parent.call(property1, …propertyN)

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

WITH ES6, how are class properties inherited from the parent?

A

class Child extends Parent, call super() in constructor

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

WithOUT ES6, how are class methods inherited from the parent?

A

Child.prototype = Object.create(Parent.prototype)

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

How do you access class properties?

A

this

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

How do you access class methods?

A

prototype

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

How to make an AJAX or async call from the browser using vanilla JS?

A

new XMLHttpRequest();

req. addEventListener(“load”, reqListener);
req. open(“GET”, “http://www.example.org/example.txt”);
req. send();

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

How to create a new regular expression

A

/something/ or new RegExp()

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

How to specify a “character” in regex?

A

\w

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

How to specify a number in regex?

A

\d - Decimal

\D - non-decimal

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

How to test a regex?

A

String.prototype.match or RegExp.prototype.exec

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

What does the i modifier do in a regex?

A

case-insensitive

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

What is the map function?

A

Get a new array by applying a transformation function on each and every element in the array (immutable)

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

What does reduce function do?

A

Reduce function reduces a given list to one final result (immutable)

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

What are the arguments to the reduce function?

A

function(accumulator, currentEl, index), initialAccumulatorValue

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

What does filter do?

A

Evaluates each element of the array against a criteria, and returns a new array with only elements that return true (immutable)

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

What is a Pure Function?

A

A function which:

  • Given the same input, will always return the same output.
  • Produces no side effects.
17
Q

How to check whether a variable is valid and not null (or) undefined?

A

Boolean(variable) or nullish coalescing operator (??) from ES2020

18
Q

What is “hoisting”?

A

Variable and function declarations are put into memory during the compile phase, but stay exactly where you typed them in your code. This it allows you to use a function before you declare it in your code. JavaScript only hoists declarations, not initializations.

19
Q

What is Event bubbling?

A

The event is handled by the innermost element first and it propagates outwards till it reaches the parent element

20
Q

When to use .bind()?

A

Use .bind() when you want that function to later be called with a certain context (useful in events)

21
Q

What does call() or apply() do?

A

Overwrites the function context

22
Q

What are the three kinds of scopes?

A

Global - available everywhere,
Block - available within a bracket enclosure (let),
Local/Function - available within a function (var)

23
Q

What is closure?

A

A function that returns another function and wraps data
A closure is an expression (most commonly, a function) that can have free variables together with an environment that binds those variables (that “closes” the expression).

24
Q

What does “this” refer to in the browser?

A

The window object

25
Q

How to iterate over an object?

A

Object.keys or a for/in loop

26
Q

What does Object.freeze do?

A

Prevent properties from being changed, added, or removed

27
Q

What does Object.seal do?

A

Prevent properties from being added, or removed but they can still be changed

28
Q

What are some Object prototype functions?

A

hasOwnProperty(), instanceof(), toString()

29
Q

What’s the difference between let and var?

A

Var has local scope, while Let has block scope

Variables declared with var keyword are hoisted (initialized with undefined) before the code is run

30
Q

Is JS pass-by-reference or pass-by-value?

A

It’s always pass by value, but for objects the value of the variable is a reference. Because of this, when you pass an object and change its members, those changes persist outside of the function.

31
Q

What is the rest parameter?

A

function(…args) allows a function to take an indefinite number or arguments as an array

32
Q

What are the types of loops?

A

for - loops through a block of code a number of times
for/in - loops through the properties of an object
for/of - loops through the values of an iterable object
while - loops through a block of code while a specified condition is true
do/while - also loops through a block of code while a specified condition is true

33
Q

What are the 7 primitive data types?

A

string, number, bigint, boolean, undefined, symbol, and null

34
Q

What is a method

A

A method is a function that is a property of an object