Truth or lies JS edition Flashcards

1
Q

Does an empty object evaluate to false?

A

No it does not, objects even empty ones evaluate to true!

if ( { } ) {
alert( “ This will run! “ );
}

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

What is a falsy value ?

A

Afalsyvalue is a value that is considered false when encountered in aBooleancontext

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

How does JavaScript create falsy and truthy values? In what contexts does JavaScript need to do this ?

A

JavaScript uses type conversion to coerce any value to a Boolean in contexts that require it, such as conditionals and loops.

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

There are 9 falsy values listed on MDN what are they ?

A
  1. The keywordfalse
  2. TheNumberzero (so, also0.0, etc., and0x0).
  3. The Number negative zero (so, also -0.0, etc., and -0x0).
  4. 0n
    The BigInt zero (so, also 0x0n). Note that there is no BigInt negative zero — the negation of 0n is 0n.
  5. ””,’’,``Emptystringvalue.
  6. null — the absence of any value.
  7. NaN — not a number.
  8. undefined — the primitive value.

9.document.all
Objects are falsy if and only if they have the [[IsHTMLDDA]] internal slot. That slot only exists in document.all and cannot be set using JavaScript.

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

What values in JavaScript are truthy ?

A

All values aretruthyexcept
false,0,-0,0n,”“,null,undefined, andNaN.

Also document.all

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