Today I Learned - Rocky Kev

TIL that JS has 8 data types

POSTED ON:

TAGS:

Data Type Example Notes
Number let n = 123; Number.MAX_SAFE_INTEGER == (253 - 1)
BigInt const bigInt = 1234567890123456789012345678901234567890n; the "n" means it's a BigInt; larger than (253-1)
String let str = "Hello"; ---
Boolean let nameFieldChecked = true; true or false
"null" let age = null; Note 1
"undefined" let age; // shows "undefined"
Objects let o = new Object() more info
Symbols let sym = Symbol('foo') Note 2

Note 1: In JavaScript, null is not a “reference to a non-existing object” or a “null pointer” like in some other languages. It’s just a special value which represents “nothing”, “empty” or “value unknown”. Similarly to undefined, null is the only value of its own type. However, null is also a liar. Due to a bug in JavaScript, it pretends to be an object.
console.log(typeof(null)); // "object" (a lie!)

Note 2: Symbols are often used to identify object properties. Often to avoid name clashing between properties, since no symbol is equal to another. Or to add properties that the user cannot overwrite, intentionally or without realizing.

reference
reference for symbols


Related TILs

Tagged:

TIL what is npm Script

Despite their high usage they are not particularly well optimized and add about 400ms of overhead. In this article we were able to bring that down to ~22ms.

TIL fancy methods to transform Javascript Objects

You can use Object.entries(), Object.keys(), Object.fromEntries()...

TIL how to hide your JS code

ONE THING TO NOTE: Encrypting a script is stronger than obfuscation, both methods are still not adequate to protect secret content. Honestly, I don't think it's worth it on a production site, and instead just go with pure server-side if you want security. But it's fascinating.