Javascript
/
Types
- 1 Fundamentals 11
-
Hello World S
-
Code structure S
-
Use strict S
-
Variables S
-
Data types S
-
Type conversions S
-
Maths S
-
Comparitions S
-
Conditional S
-
Loops S
-
Functions S
- 2 Testing 2
-
Mocha S
-
Nested describe S
- 3 Objects 4
-
Basics S
-
Reference S
-
Methods S
-
Constructor S
- 4 Types 5
-
Primitives S
-
Numbers S
-
Strings S
-
Arrays S
-
Json S
- 5 Classes 3
-
Constructor S
-
Binding S
-
Inheritance S
S
R
Q
Javascript Types Primitives
Object wrappers for each primitive type Objects are heavier than primitives a = 'abc'; // Wrapper called b = a.toUpperCase(); // Object destroyed
Objects
Objects are heavier than primitives.
/**
* One of the best things about objects is that ...
* we can store a function as one of its properties
* But that come with a cost ...
* Objects are heavier than primitives
*/
let user = {
name: 'John',
message: () => console.log("Hello World"),
}
user.message(); // Hello World
Wrappers
Object wrappers allow us to access primitives using methods.
/**
* Object wrappers for each primitive type:
* String, Number, Boolean, etc
* Primitives can provide methods and still remain lightweight
*/
let a = 'Hello World'; // Wrapper called
let b = a.toUpperCase(); // Object a destroyed, primitive remains
let c = 1.23456; // Wrapper called
let d = c.toFixed(2);
console.log(b); // HELLO WORLD
console.log(n2); // 1.23
➥ Questions