Skip to content

Commit 720bd02

Browse files
refactor: datatype
1 parent ea1da0c commit 720bd02

16 files changed

+20
-10
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

05_datatype/1_type_of_datatype.js 5_datatype/1_type_of_datatype.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ let myBoolean2 = false;
2828
const mySymbol = Symbol();
2929

3030
// Traditional Datatype: numbers, string & boolean
31-
// Standalone value: undefined, null, empty string `""`
31+
// Standalone value: undefined, null, empty string `""`, NaN
3232

3333
// Undefined
3434
let myUndefined1 = undefined;
File renamed without changes.
+17-7
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,42 @@
11
// NaN (Not a Number)
22

33
// What
4-
// - `NaN` stands for "Not-a-Number." It's a special value in JavaScript that shows up when you do something that doesn't make sense with numbers.
4+
// - `NaN` stands for Not-a-Number.
5+
// - It's a standalone value in JavaScript that shows up when you do something that doesn't make sense with numbers.
56

67
// Why
7-
// - JavaScript uses NaN to tell you when a math operation can't give a proper number answer, like dividing zero by zero.
8+
// - NaN is for when a math operation can't give a proper number answer, for example dividing zero by zero. At that time JavaScript will return NaN.
89

910
// How
1011
// - When you try to do math with things that aren't numbers, like dividing text by a number, you get NaN. It's like JavaScript's way of saying "I can't give you a real number because this doesn't work."
1112

12-
// Note
13-
// - Be careful with NaN. If you use it in a calculation, the final result will also be NaN. Also, comparing NaN with other NaN values using === won't work as expected.
14-
1513
// Example
1614
let division = 0 / 0; // This division results in NaN
1715
console.log(division); // Output: NaN
1816

17+
// Note
18+
19+
// NaN is Number (But Short Of)
20+
// - In JavaScript, typeof NaN returns "number" even though it represents "Not a Number."
21+
// - This is because NaN is a special numeric value used to indicate an invalid result.
22+
// - It occupies a space within the number system but doesn't represent a valid mathematical value.
23+
// - Be careful with NaN. If you use it in a calculation, the final result will also be NaN.
24+
1925
// NaN in Comparisons
20-
// - For example, NaN === NaN returns false, and NaN !== NaN returns true. To check if a value is NaN, use the isNaN() function or the Number.isNaN() static method.
26+
// - Interestingly, even NaN compared to itself using comparison operators like === or !== returns false.
27+
// - This is because NaN is not equal to anything, including itself.
28+
// - For example, NaN === NaN returns false, and NaN !== NaN returns true.
29+
// - To check if a value is NaN, use the isNaN() method or the Number.isNaN() static method.
2130

2231
let result = 0 / 0; // This division results in NaN
2332
console.log(result); // Output: NaN
2433
console.log(typeof result); // Output: "number"
2534

26-
console.log(isNaN(result)); // Output: true
2735
console.log(result === NaN); // Output: false
2836
console.log(result !== NaN); // Output: true
2937

38+
// How to Handle NaN (Recommended)
39+
console.log(isNaN(result)); // Output: true
3040
console.log(Number.isNaN(result)); // Output: true
3141

3242
// - It's important to handle NaN in your code, especially when dealing with user input or calculations, to ensure that your program behaves as expected and doesn't produce unexpected results due to the presence of NaN.
File renamed without changes.
File renamed without changes.

05_datatype/02_symbol/01_symbol.js 5_datatype/symbol/1_symbol.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
// - Symbols are used to create unique identifiers, which can be used as property keys for object properties. They help prevent naming collisions and enable the creation of private object members.
88

99
// How
10-
// - Symbols are created using the Symbol() function, optionally with a description as an argument. Each symbol value returned by Symbol() is guaranteed to be unique.
10+
// - Symbols are created using the Symbol() construction, optionally with a description as an argument. Each symbol value returned by Symbol() is guaranteed to be unique.
1111

1212
// Syntax
13-
const symbolName = Symbol("Identifier value");
13+
const symbolName = Symbol("description argument");
1414

1515
// Example
1616
// Create a car object

0 commit comments

Comments
 (0)