Must you define a data type when declaring a variable in JavaScript?
Asked
Active
Viewed 907 times
1
-
No, you can define variables in javascript like `var myVariable` – kalenpw Feb 26 '17 at 04:25
-
to say "you can" suggests there's another option - there isn't ... variables are untyped – Jaromanda X Feb 26 '17 at 04:31
-
@jaromandaX Good point, you MUST declare variables with the var keyword, but is now too late to edit my comment – kalenpw Feb 26 '17 at 04:33
-
of course, there's var, let and const now :p and not using any of those is equivalent to window.xxx (in a browser) – Jaromanda X Feb 26 '17 at 04:34
3 Answers
0
No, you ca go with just
var x = 5;
The interpreter would guess what type the var is.

Terminus
- 925
- 10
- 23