How to check type of variable in Javascript?

Member

zita

by zita , in category: JavaScript , a month ago

How to check type of variable in Javascript?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by craig , a month ago

@zita You can use keyword typeof to check type in javascript, some examples:


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
typeof "string variables"
// 'string'
typeof 100
// 'number'
typeof false
// 'boolean'
typeof {}
// 'object'
typeof undefined
// 'undefined'
typeof alert
// 'function'