type of variable js

JavaScript
// get type of variable

var number = 1
var string = 'hello world'
var dict = {a: 1, b: 2, c: 3}

console.log(typeof number) // number
console.log(typeof string) // string
console.log(typeof dict)   // objectfunction doSomething(x) {
  if(typeof(x) === 'string') {
    alert('x is a string')
  } else if(typeof(x) === 'number') {
    alert('x is a number')
  }
}//retourne le type de la variable

let number = 1;
let string = "bonjour";
let bool = true;
let dict = { a: 1, b:2 };

console.log(typeof(number));//renvoie Number
console.log(typeof(string));//renvoie String
console.log(typeof(bool));//renvoie Boolean
console.log(typeof(dict));//renvoie Object

//cas spécial

console.log(typeof(NaN));//NaN = Not A Number renvoie Numbertypeof operandotypeof("iAmAString");//This should return 'string'
//NO camelCase, as it is a JS Keyword> typeof "foo"
"string"
> typeof true
"boolean"
> typeof 42
"number"

Source

Also in JavaScript: