type of variable js
// 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"
Also in JavaScript:
- how to make a sprite javascript
- dynamic vue js maintenance mode
- object get property with max value javascript
- how to flatten array in javascript using foreach loop
- javascript push is not a function
- store the text from a form jquery
- identify chrome on android using javascript
- Generate random whole numbers javascript
- javascript glow
- type of variable js
- print array without brackets javascript
- how to use cordova screen shot
- semantic ui dropdown value
- javascript create object from key value pairs
- what is package.lock.json
- is a letter javascript
- remove object from array by name javascript
- jquery document ready shorthand
- queryselector function in javascript
- javascript to redirect to another page after 5 seconds
- filter geojson programmatically
- javascript how to set session variable
- javascript atualize array
- componentWillUnmount functional component for asynchronous requests