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
Variables don’t have types. The values have types. remember to use typeof operator.
Numbers
5 0b101 0o5 0x5 5e7
1. ```
10 * "string" => NaN
10/0 => Infinity
-10/0 => -Infinity
- Strings
- `"" ’’ ```
let s = “Jane is good” s.length //12 s.toLowerCase() s.toUpperCase()
1. ## Booleans
1. ```
true
false
"" 0 NaN 0n // Bigint value null undefined false
1. ## Objects
1. ```
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; // 7
1. `newPerson`
1. `person`
1. ```
let name = "Jane";
let age = 8;
let oldPerson = {
name,
age,
}
let somePerson = null; typeof somePerson; // ‘object’
1. ### Arrays
1. ```
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
1. ## Functions
1. ```
function add(x, y){
return x+y;
}
let add1 = function(x, y){ return x+y; }
1. ```
let add2 = (x, y) => {
return x+y;
}
Undefined
typeof blah; //undefined let x; //undefined blah.x //undefined blah[0] //undefined typeof undefined; // undefined typeof null; // object
1. ## Bigints
1. ` 10n `
1. ```
10n + BigInt(2) // 12n
Symbols
let mySym = Symbol("aGoodSymbol"); mySym; // Symbol(aGoodSymbol) let mySym1 = Symbol.for("aVeryGoodSymbol");
