JavaScript Syntax

If JavaScript is to use in HTML than JavaScript can be implemented using JavaScript statements that are placed within the <script>... </script>HTML tags in a web page.

While it's best way to used JavaScript in HTML file is, You can place the <script> tags, containing your JavaScript, anywhere within your web page, but it is normally recommended that you should keep it within the <head> tags.

Basic example of javascript

Basically the <script> tag tell the browser program to start interpreting all the text between these tags as a script. A simple syntax of your JavaScript will appear as follows.

<script ...>
 JavaScript code here...
</script>


Whitespace and Line Breaks

One of the biggest advantage of JavaScript is JavaScript ignores spaces, tabs, and newlines that appear in JavaScript programs. And also you can use spaces, tabs, and newlines freely in your program and you are free to format and indent your programs in a neat and consistent way that makes the code easy to read and understand.


Semicolons are Optional

As compare to other programming languages, one of the biggest advantage of JavaScript syntax is, simple statements in JavaScript are generally followed by a semicolon character, just as they are in C, C++, and Java. JavaScript, however, allows you to omit this semicolon if each of your statements are placed on a separate line. For example, the following code could be written without semicolons.

<script language="javascript" type="text/javascript">
 var x, y, z;  // Declare Variables
 x = 5; y = 6;  // Assign Values
 z = x + y;  // Compute Values
</script>


Case Sensitivity

Just like other languages like JAVA, C++, JavaScript is a case-sensitive language. This means that the language keywords, variables, function names, and any other identifiers must always be typed with a consistent capitalization of letters. So the identifiers Time and TIME will convey different meanings in JavaScript.








The Best

Comment here

If you have any query, if you want to know something about any of technical course related to computer science field, if you have any suggestion about relevant to uploaded content or if you anything wrong here (any mistake in content) than please contact us. Keep in mind, comment should be according to community guidelines.