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
10 * "string" => NaN
10/0 => Infinity
-10/0 => -Infinity
all numbers stored as 64bit floating point. never compare decimal numbers.
- Strings
Can be defined with "" '' ``
let s = "Jane is good"
s.length //12
s.toLowerCase()
s.toUpperCase()
Booleans
true
false
Falsey Values
""
0
NaN
0n // Bigint value
null
undefined
false
Objects
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
Note 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
Functions
function add(x, y){
return x+y;
}
let add1 = function(x, y){
return x+y;
}
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
Bigints
add a single lowercase n at end of number: 10n
10n + BigInt(2) // 12n
Symbols
No two symbols are ever equal.
let mySym = Symbol("aGoodSymbol");
mySym; // Symbol(aGoodSymbol)
let mySym1 = Symbol.for("aVeryGoodSymbol");
http:///wiki/?jsdatatypes