How to check variable type in TypeScript

1 Answer

0 votes
const b = true; 
const n = 84938;
const s = "typescript";
 
const obj = {
  id: 1234,
  name: "ben",
  salary: 13900,
  work: true
}
 
 
console.log(typeof b); 
console.log(typeof n); 
console.log(typeof s); 
console.log(typeof obj); 
console.log(typeof obj.id); 
console.log(typeof X); 
 
    
        
        
        
/*
run:
    
"boolean"
"number"
"string"
"object"
"number" 
"undefined"
    
*/

 



answered Feb 4, 2022 by avibootz

Related questions

1 answer 299 views
1 answer 177 views
1 answer 282 views
1 answer 199 views
1 answer 214 views
2 answers 395 views
...