Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,926 questions

51,859 answers

573 users

How to use typeof operator in JavaScript

1 Answer

0 votes
console.log(typeof 456);
console.log(typeof 3.14);
console.log(typeof '2'); // string
console.log(typeof Number('2')); // number
console.log(typeof Infinity); // number

console.log(typeof '');
console.log(typeof 'javascript');
console.log(typeof String(12));

console.log(typeof true);

console.log(typeof n);

console.log(typeof {x: 98});
console.log(typeof [5, 7, 0, 2]);
console.log(typeof new Date());

console.log(typeof function() {});
console.log(typeof class C {});
console.log(typeof Math.cos);


let x = 12;

console.log(typeof x + ' abc'); 
console.log(typeof (x + ' abc'));




/*
run:

"number"
"number"
"string"
"number"
"number"
"string"
"string"
"string"
"boolean"
"undefined"
"object"
"object"
"object"
"function"
"function"
"function"
"number abc"
"string"

*/

 



answered Nov 20, 2020 by avibootz
edited Nov 20, 2020 by avibootz
...