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,884 questions

51,810 answers

573 users

How to find the type of a variable in JavaScript

8 Answers

0 votes
const n = 30;

console.log(typeof(n));



 
/*
run:
 
"number"
 
*/

 



answered Jun 5, 2015 by avibootz
edited Jul 15, 2022 by avibootz
0 votes
const n = 3.14;

console.log(typeof(n));



 
/*
run:
 
"number"
 
*/

 



answered Jun 5, 2015 by avibootz
edited Jul 15, 2022 by avibootz
0 votes
const s = "javascript";

console.log(typeof(s));



 
/*
run:
 
"string"
 
*/

 



answered Jun 5, 2015 by avibootz
edited Jul 15, 2022 by avibootz
0 votes
const b = false;

console.log(typeof(b));



 
/*
run:
 
"boolean"
 
*/

 



answered Jun 6, 2015 by avibootz
edited Jul 15, 2022 by avibootz
0 votes
const arr = ["java", "javascript", "c"];  

console.log(typeof(arr));



 
/*
run:
 
"object"
 
*/

 



answered Jun 6, 2015 by avibootz
edited Jul 15, 2022 by avibootz
0 votes
const arr = [1, 2, 3];  

console.log(typeof(arr));



 
/*
run:
 
"object"
 
*/

 



answered Jun 6, 2015 by avibootz
edited Jul 15, 2022 by avibootz
0 votes
const obj = {name:'Tom', age:47};  

console.log(typeof(obj));



 
/*
run:
 
"object"
 
*/

 



answered Jun 6, 2015 by avibootz
edited Jul 15, 2022 by avibootz
0 votes
let v;

console.log(typeof(v));



 
/*
run:
 
"undefined"
 
*/

 



answered Jun 6, 2015 by avibootz
edited Jul 15, 2022 by avibootz

Related questions

1 answer 84 views
1 answer 157 views
1 answer 139 views
1 answer 157 views
1 answer 131 views
131 views asked May 22, 2023 by avibootz
1 answer 120 views
120 views asked Aug 24, 2020 by avibootz
...