The script tag takes two important attributes
Let us write our class example to print out “Hello World”.
Next, we call a function document .write which writes a string into our HTML document. This function can be used to write text, HTML, or both .So above code will display following result:
Whitespace and Line Breaks
Because you can use spaces, tabs, and newlines freely in your program so you are free to format and indent your program in a neat and consistent way that makes the code easy to read and understand.
Semicolons are optional
But when formatted in a single line as follows, the semicolons are required:
It is a good programming practice to use semicolons.
Script in <head> … </head> section
Script in <body> … <.body> Section
Script in <body> …. </body> and <head> ….. </head> sections.
Script in and external file and then include in <head>--- </head> section.
If you want to have a script run on some event, such as when a user clicks somewhere, then you will place that script in the head as follows:
<input type=”button” onclick=”sayHello()” value=”Say Hello” />
<p>This is webpage body </p>