Skip to content
Advertisement

How to use typed variables in javascript?

Is there any way to use typed variables in javascript? Like integer, string, float…

Advertisement

Answer

JavaScript variables are not typed.

JavaScript values are, though. The same variable can change (be assigned a new value), for example, from uninitialized to number to boolean to string (not that you’d want to do this!):

var x;       // undefined
x = 0;       // number
x = true;    // boolean
x = "hello"; // string
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement