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'
document.write(rank)

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.

raja
Published on 18-Jan-2018 08:58:50
Advertisements