Evaluating Expression Syntax Flashcards

1
Q

Differences between ‘Undefined’ and ‘Null’? When would a return value be ‘Undefined’ vs. ‘Null’?

A
  • ‘Null’ is considered a value; can be assigned
  • Typeof null is object; means ‘no object’
  • ‘Null’ is return value for undefined objects or invalid expressions
  • Undefined indicates that no value assigned
  • Undefined is returned for primitives
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Undefined != Null

A

True. ‘Null’ is a value and has type of object. Undefined has no value.

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

NaN != NaN

A

True. NaN can only be used in comparison expressions

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

Bool value of ‘Null’

A

False

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

Bool value of ‘Undefined’

A

False

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

ES6 method to check NaN?

A

Number.isNAN()

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

Default return value of a function if not specified?

A

Undefined

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

Are semicolons required after statements?

A

No, but they’re recommended for clarity

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

What comparison is safe to evaluate null?

A

Strict equality (returns 0 if type coersion is applied by ==)

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

Type of NaN?

A

Number

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

Type of Infinity?

A

Number (+ or - infinity)

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

In dot notation, everything to the left of a dot is ________

A

an object

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

Numeric value of ‘undefined’

A

NaN

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

Numeric value of ‘null’

A

0

ex: value of a null variable used in a calculation, value if type coercion is applied

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

What is the bool value of an object?

A

True

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

Name 6 things considered ‘falsey’

A

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

17
Q

Operator to concat strings

A

+

18
Q

Escape character

A

\ backslash

19
Q

What type of expression is…

{ foo: bar(3, 5)}

A

Object literal. Expression that looks like a statement

20
Q

What type of expression is…

function foo( ){ }

A

Named function expression

21
Q

let n = “25”

  1. Convert to number with single operator
  2. Convert to number with method
A
  1. +n //not ideal because it’s unclear

2. number(n) //verbose but clear

22
Q

Preferred quote style for JS?

A

Single

23
Q

Preferred quote style for HTML?

A

Double

24
Q

Quote style for JSON?

A

Double (required)

25
Q

What is the difference between these function definitions? Do they have the same scope?

A) var square = function(x) { return x * x; };

B) function square(x) {
return x*x;
}

A

A) Expression with function keyword assigned to variable

B) Function declaration with keyword

  • var ‘square’ has function scope; as a variable, it cannot be hoisted. ; function ‘square’ can be hoisted
26
Q

Can a function be used in an arbitrary expression?

A

Yes, a function is considered a ‘value’. It can be part of an expression (not called like a method).