Can I declare JavaScript variables as specific types?

JavascriptWeb DevelopmentFront End Technology

JavaScript variables do not have types. The values have types. Here’s how JavaScript variables are declared −

var rank = 5
var name =”John”

You can still write it like this −

var rank = 5
rank = ‘first'

As you can see above, it wouldn’t be of any benefit to specify the type in a variable declaration. This is because the type is dictated by the variable's value.

Updated on 15-Jun-2020 05:37:09