PROGRAMMING

  minte9
learningjourney




S R Q

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    
Last update: 65 days ago
Numbers