Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

valueof js

/* ValueOf is a prototype that give the Primitive value of a variable
where typeof will give only it types e.g 
*/

const numObj = new Number(42); // let numObj = 42; will work too
console.log(typeof numObj); // output: "object"

const num = numObj.valueOf();
console.log(num);// output: 42

// it works with any type that have a primitive type

let str = new String("Hello"); // let str = "Hello"; will work too 
console.log(str.valueOf()) // output: "Hello"
 
PREVIOUS NEXT
Tagged: #valueof #js
ADD COMMENT
Topic
Name
8+2 =