More Basics Flashcards

1
Q

How do you get all the keys in an object?

A

Object.getOwnPropertyNames() or Object.keys() - returns an array of object keys

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

How do you get all the values in an object?

A

Object.values() - returns an array of object values

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

How do you get all keys and values in an object?

A

Object.entries() returns an array of [key, value]

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

What is hoisting?

A

Hoisting is JavaScript’s default behavior of moving all declarations to the top of the current scope (to the top of the current script or the current function).

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

When are hoisted variables initialized?

A

JavaScript only hoists declarations, not initializations. Initializations occur as written in the code.

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

What happens due to hoisting when you declare a variable with let?

A

Variables defined with let and const are hoisted to the top of the block, but not initialized.

Meaning: The block of code is aware of the variable, but it cannot be used until it has been declared.

Using a let variable before it is declared will result in a ReferenceError.

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

What happens due to hoisting when you declare a variable with const?

A

Variables defined with let and const are hoisted to the top of the block, but not initialized.

Meaning: The block of code is aware of the variable, but it cannot be used until it has been declared.

Using a const variable before it is declared, is a syntax errror, so the code will simply not run.

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

What does Javascript evaluate as a boolean False?

A

false, 0, ‘ ‘, “ “, null, undefined, NaN

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

What does Javascript evaluate as a boolean True?

A

‘0’, ‘false’, [ ], { }, function() { }

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

What is the rule of precision for decimal numbers?

A

Always treat them as approximations.

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

What does the template literal ${} do inside a string?

A

Evaluates whatever is inside the {}

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

What is one value in javascript that doesn’t equal itself?

A

NaN

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

How do you test whether a variable has a real value?

A

== or != null

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

What does the || operator do?

A

Returns the left value if true and the right value otherwise.

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

What are legal characters for binding names?

A

Letters, numbers, $, and _

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

What functions convert data to different types?

A

Number, String, Boolean

17
Q

What function call evaluates if the input is a number?

A

Number.isNan (use ! to determine if the input is a number)

18
Q

What is lexical scoping?

A

Each local scope can see the local scopes that contain it, and all scopes can see the global scope.

19
Q

What happens when you make a function call with extra parameters?

A

Nothing, the function ignores the extra values.

20
Q

How do you copy all properties from one object to another?

A

Object.assign(Original, Copy)

21
Q

What does == do when applied to Objects?

A

Checks whether they point to the same Object, not whether the contents are equivalent.

22
Q

What are the two ways to access a value’s properties?

A

Bracket and dot notation

23
Q

What’s the difference between the bracket and dot notation?

A

The word after the dot is the literal name of the property, the data in brackets is evaluated. For dot notation, the word should be a valid binding (not a number or variable).

24
Q

What happens if you read an object property that doesn’t exist?

A

You get undefined.

25
Q

What does the binary in operator do on an object?

A

It returns true or false if the object has or doesn’t have a property.

26
Q

How do you get all property names in an object?

A

Object.keys(objName) returns an array of object keys.

27
Q

What types of values are immutable and what does that mean?

A

Numbers, Strings, booleans. You can’t change them but you can combine them and derive new values from them. For example, you can’t change the string “cat” to “rat.”

28
Q

What happens if you pass concat an argument that isn’t an array?

A

It treats the object like a one element array.

29
Q

What is unique about using indexOf on a string?

A

It can search for multiple-character patterns - i.e “three”.indexOf(“ee”);

30
Q

What do string.split and string.join do?

A

split the string into an array strings every time (arg) appears and join an array of strings into string with (arg) as a separator.

31
Q

how do you add a string to itself?

A

string.repeat(x) - repeats a string x times

32
Q

What are restrictions on JSON bindings?

A

All property names have to be surrounded by double quotes and only simple expressions are allowed (no function calls, bindings, or anything requiring computation.