Whitespace and Line Breaks:
JavaScript ignores spaces, tabs, and newlines that appear in JavaScript programs.
Because you can use spaces, tabs, and newlines freely in your program so you are free to format and indent your programs in a neat and consistent way that makes the code easy to read and understand.
JavaScript ignores spaces, tabs, and newlines that appear in JavaScript programs.
Because you can use spaces, tabs, and newlines freely in your program so 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:
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 your statements are each placed on a separate line. For example, the following code could be written without semicolons
<script language="javascript" type="text/javascript">
<!--
var1 = 10
var2 = 20
//-->
</script>
But when formatted in a single line as follows, the semicolons are required:
<script language="javascript" type="text/javascript">
<!--
var1 = 10; var2 = 20;
//-->
</script>
Note: It is a good programming practice to use semicolons.
Case Sensitivity:
JavaScript is a case-sensitive language. This means that language keywords, variables, function names, and any other identifiers must always be typed with a consistent capitalization of letters.
So identifiers Time, TIme and TIME will have different meanings in JavaScript.
NOTE: Care should be taken while writing your variable and function names in JavaScript.
Comments in JavaScript:
JavaScript supports both C-style and C++-style comments, Thus:
JavaScript supports both C-style and C++-style comments, Thus:
2.Any text between the characters /* and */ is treated as a comment. This may span multiple lines.
3.JavaScript also recognizes the HTML comment opening sequence <!--. JavaScript treats this as a single-line comment, just as it does the // comment.
4.The HTML comment closing sequence --> is not recognized by JavaScript so it should be written as //-->.
There is a flexibility given to include JavaScript code anywhere in an HTML document. But there are following most preferred ways to include JavaScript in your HTML file.
- 1.Script in <head>...</head> section.
- 2.cript in <body>...</body> section.
- 3.cript in <body>...</body> and <head>...</head> sections.
- 4.cript in and external file and then include in <head>...</head> section.
0 comments:
Post a Comment