Basic but vague

1.typeof null

object

This is a legacy issue, null is not actually an object.

2.”==” & “===”

  • former: loose

  • latter: strict

console.log(18 == ‘18’); // true

console.log(18 === ‘18’); // false

3.typeof NaN

number

4.String concatenation of the + operator

1
2
console.log('5' + 5);//"55"
console.log('5' - 5);//0

“+” is different from “-“ in this field.

5.”undefined” & “null”

  • former: declared but not assigned

  • latter: declared and assigned a null value

6.NaN === NaN ?

amazingly wrong

we need to use a func called “isNaN()”

7.boolean about “0” & “ “

both false

Challenge

  • declare function prompt(message?: string, _default?: string): string | null;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// const favourite = Number(prompt("What's your favourite number?"));
// console.log(typeof favourite);
// // "number" if input is a valid number
// // otherwise "number" with value NaN1

// I can not run above code in VScode, so I find another way follow.

const readline = require('readline');

const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});

rl.question("What's your favourite number? ", (answer) => {
const favourite = Number(answer);
console.log(typeof favourite);
// "number" if input is a valid number
// otherwise "number" with value NaN
rl.close();
});