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 210 views
1 answer 86 views
1 answer 181 views
1 answer 124 views
1 answer 134 views
2 answers 251 views
...