get type of var js
function doSomething(x) {
if(typeof(x) === 'string') {
alert('x is a string')
} else if(typeof(x) === 'number') {
alert('x is a number')
}
}> typeof "foo"
"string"
> typeof true
"boolean"
> typeof 42
"number"
if(typeof bar === 'number') {
//whatever
}typeof("string"); //string
typeof(123); //numbervar x = 12345;
console.log(typeof x) // number
x = 'string';
console.log(typeof x) // string
x = { key: 'value' };
console.log(typeof x) // object
Also in JavaScript:
- how to get window size in react js
- run on load js
- javascript on script loaded
- Module Error (from ./node_modules/eslint-loader/dist/cjs.js):
- js some array
- javascript number format
- Unterminated quote at columns 0-8 ['MM-yyyy] in expression ['MM-yyyy]
- express and node pakages
- javascript document object model getElementsByClassName
- how to add class to button in javascript
- difference between key and code in javascript
- get caret position javascript
- javascript truncate string full word
- javascript empty function
- nestjs version
- javascript sum array of objects
- javascript Compare two arrays regardless of order
- Cannot deserialize the current JSON array (e.g. [1,2,3]) into type
- javascript fs write file with folder
- ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'ngIf: [object Object]'. Current value: 'ngIf: true'.
- vuejs filter array by dates
- javascript textarea.append
- variables 2 python .Bartolome sintes Marco
- nextjs starter template with auth