JavaScript Basics - The tricky stuff

Some cards for the tricky things of JS.

Some cards for the tricky things of JS.


O. W.
Flashcards
9
Students
4
Language
German
Category
Computer Science
Level
University
Created / Updated
13.06.2017 / 16.06.2022

Flashcards

What's the console output for:

console.log(null == undefined);

true

"==" is used to compare values. null and undefined have exactly the same values.

What's the console output for:

console.log(null === undefined);

false

"===" is used to compare the value and the type. null and undefined have the same value but not the same type.

What's the console output for:

var test = NaN;

console.log(typeof test);

"number"

NaN really is of type number. You can think of it kind of like an error message for calculations.

What's the console output for:

var test = null;

console.log(typeof test);

"object"

null is of type object.

What's the console output for:

var test = undefined;

console.log(typeof test);

"undefined"

Is the following example working?

var test = 10;

console.log(test);

test = '5';

console.log(test);

yes, it works! It's possible to change types of an existing variable in JavaScript.

Is the following code working?

test = 10;

console.log(test);

var test;

yes, it's going to work. This behavior is called hoisting.

What is the output for:

console.log(NaN == NaN);

false

There's a special rule in JS which says that NaN is never similair to NaN.

What is the output for:

console.log(0 == null);

false

null can't be compared in JavaScript.

There's just one exception: console.log(undefined == null) would be true.

Study