JavaScriptissä on muutamia perustyyppejä:
Tyyppi selviää typeof-operaattorilla
typeof
typeof-operaattori palauttaa string-arvon
string
const num = 123; console.log(typeof num); // => "number"
typeof x
Esimerkki
'undefined'
undefined, let moo
undefined
let moo
'object'
{}, [], new Date(), /^abc$/, null
{}
[]
new Date()
/^abc$/
null
'boolean'
true
'number'
123
'string'
'moo'
'symbol'
Symbol('foo')
'function'
function f() {}
Last updated 7 years ago