Built in constructors

// String
const name1 = 'Jeff';
const name2 = new String('Jeff');

name2.foo = 'bar'
console.log(name1);
console.log(typeof name2);

if(name2 === 'Jeff'){
    console.log('YES');
} else {
    console.log('NO');
}

// Number
const num1 = 5;
const num2 = new Number(5);

// Boolean
const bool1 = true;
const bool2 = new Boolean(true);

console.log(bool1);
console.log(bool2);

// Functions
const getSum1 = function(x, y){
    return x + y;
}
//console.log(getSum1(3, 2));

const getSum2 = new Function('x', 'y', 'return 3 + 3');

// Object
const john1 = {name: "John"};
const john2 = new Object({name: "John"});
console.log(john2);

// Arrays
const arr1 = [1,2,3,4,5];
const arr2 = new Array(1,2,3,4,5);
console.log(arr2);

// Regular Expressions
const re1 = /\w+/;
const re2 = new RegExp('\\w+');
console.log(re2);

Was this page helpful?

Reader Interactions

Leave a Reply

Your email address will not be published. Required fields are marked *