JavaScript Primitive Data Types
Code Snippets
Data Types
// Primitive
console.log("Number", typeof 0);
console.log("BigInt", typeof 0n);
console.log("String", typeof "faheem.dev");
console.log("Boolean", typeof false);
console.log("Symbol", typeof Symbol("faheem"));
console.log("Undefined", typeof undefined);
// Special Primitive
console.log("Null", typeof null);
// Data Structure
console.log(Object.prototype.__proto__);
console.log(Function.__proto__.__proto__.__proto__);
BigInt
max = Number.MAX_SAFE_INTEGER;
console.log("Number", max, max + 1, max + 2, (max + 1) === (max + 2));
bigMax = BigInt(max);
console.log("BigInt", bigMax, bigMax + 1n, bigMax + 2n, (bigMax + 1n) === (bigMax + 2n));
Symbol
const subs = Symbol("Subscribers");
const faheem = {
name: "Faheem",
[subs]: 0,
[Symbol()]: "hi@faheem.dev"
};
console.log(Object.entries(faheem));
console.log(Object.getOwnPropertySymbols(faheem));
Object.getOwnPropertySymbols(faheem).forEach(symbol => {
console.log(symbol, faheem[symbol]);
});
Helpful Links
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures
https://stackoverflow.com/questions/801032/why-is-null-an-object-and-whats-the-difference-between-null-and-undefined