This code will produce the following result on page − "Welcome to Engineering World!"
<html> <body> <script> document.write("Welcome to Engineering World!"); </script> </body> </html>
But when formatted in a single line as follows, you must use semicolons −
Note − It is a good programming practice to use semicolons.
Follow Tools → Internet Options from the menu.
Select Security tab from the dialog box.
Click the Custom Level button.
Scroll down till you find Scripting option.
Select Enable radio button under Active scripting.
Finally click OK and come out
Open a new tab → type about: config in the address bar.
Then you will find the warning dialog. Select I’ll be careful, I promise!
Then you will find the list of configure options in the browser.
Click the Chrome menu at the top right hand corner of your browser.
Click Show advanced settings at the end of the page.
Under the Privacy section, click the Content settings button.
Follow Tools → Preferences from the menu.
Select Advanced option from the dialog box.
Select Content from the listed items.
Finally click OK and come out.
Numbers, eg. 123, 120.50 etc.
Strings of text e.g. "This text string" etc.
Boolean e.g. true or false.
You can also declare multiple variables with the same var keyword as follows −
Storing a value in a variable is called variable initialization. You can do variable initialization at the time of variable creation or at a later point in time when you need that variable. For instance, you might create a variable named money and assign the value 2000.50 to it later. For another variable, you can assign a value at the time of initialization as follows.
Note − Use the var keyword only for declaration or initialization, once for the life of any variable name in a document. You should not re-declare same variable twice.
Local Variables − A local variable will be visible only within a function where it is defined. Function parameters are always local to that function.
Within the body of a function, a local variable takes precedence over a global variable with the same name. If you declare a local variable or function parameter with the same name as a global variable, you effectively hide the global variable. Take a look into the following example