Javascript | Javascript kata |Node JS | Data Types | Variables | Control Flow | Scope and Environment | Objects | Functions | Events | Prototypal Inheritance | Three.js | 3DE Code Editor |
Javascript Data Types
There are 8 fundamental data types:- Numbers, Strings, Booleans, Objects, Functions, Undefined, Bigints, Symbols
Numbers
- Strings Can be defined with "" '' ``
Booleans
Objects
Functions
Undefined
Bigints
add a single lowercase n at end of number: 10n
Symbols
No two symbols are ever equal.
5 0b101 0o5 0x5 5e7
10 * "string" => NaN 10/0 => Infinity -10/0 => -Infinityall numbers stored as 64bit floating point. never compare decimal numbers.
let s = "Jane is good" s.length //12 s.toLowerCase() s.toUpperCase()
true falseFalsey Values
"" 0 NaN 0n // Bigint value null undefined false
let person ={ name: "Jane", // don't forget the commas! age: 5 } person.name; person["name"]; person.age = 6; let newPerson = person;
newPerson.age = 7; person.age; // 7Note that newPerson points to the same Object as person
let name = "Jane"; let age = 8; let oldPerson = { name, age, }
let somePerson = null; typeof somePerson; // 'object'This is a short cut.
Arrays
let a = [0, 1]; // undefined a.length; a[0] = 2; a.push(3); a.pop(); a.unshift(4) a.shift(). a.indexOf(1);
map filter sort
function add(x, y){ return x+y; }
let add1 = function(x, y){ return x+y; }
let add2 = (x, y) => { return x+y; }
typeof blah; //undefined let x; //undefined blah.x //undefined blah[0] //undefined typeof undefined; // undefined typeof null; // object
10n + BigInt(2) // 12n
let mySym = Symbol("aGoodSymbol"); mySym; // Symbol(aGoodSymbol) let mySym1 = Symbol.for("aVeryGoodSymbol");
11apr23 | admin |