JavaScript ignores spaces, tabs, and newlines that appear in JavaScript code. 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
S tatements in JavaScript generally end with a semicolon character, similar to C, C++, and Java. JavaScript, however, allows you to omit this semicolon if each of your statements are placed on a separate line.
- Example 1
- varA = "Learn"
- varB = "JAScript"
- Example 2
- varA = "Learn" varB = "JAScript"
- Example 3
- varA = "Learn"; varB = "JAScript";
In the above examples Example 1 and 3 will run while example 2 will generate error.
Case Sensitivity
JavaScript is a case-sensitive language. This means that the language keywords, variables, function names, and any other identifiers must always be typed in consistency.
- Example 4
- var myVar = 5;
- var myvar = 10;
- print(myVar);
- print(myvar);
Example 5
function myFunction(){
return 5;
- };
- function myfunction(){
- };
In the above example myVar and myvar and two different variables and they will print 5 and 10 respectively. In example 5, the two functions are totally different
Comments in JavaScript
JavaScript supports both C-style and C++-style comments.
- Any text between a // and the end of a line is treated as a comment and is ignored by JavaScript.
- Any text between the characters /* and */ is treated as a comment. This may span multiple lines.
- Example 6
- //This is a single line comment
- var val = 5;
- var name = "Tree";
- var combined = val+name;
- print(combined);
- /*
- This
- is
- a
- multiline
- comment
- */
No comments:
Post a Comment