Variable in JavaScript

Variable in JavaScript
Rating: 3 - 2 Votes

Variable in JavaScript

JavaScriptTo create a variable in JavaScript, we make use of var keyword.  Unlike other programming languages, where you need to be specific of data type before assigning any value, you can use var keyword for all kind of values.  Behind the scenes, it will automatically convert your variable to its original data type and perform the desired action depending upon whether it is addition or concatenation.  JavaScript is case-sensitive scripting language.  So, you must make sure that you should use variables, functions, event handlers, object properties name exactly as you declared them.

Now, we are going to assign a string value “Hello World” to a variable and pass it to the alert function as parameter.  JavaScript Sample code is given below.