Sunday, 24 July 2016

JavaScript Comments, Semicolon, White space and Line breaks

Comments
Commented code is ignored at the time of program execution. It is used to provide additional information such as description of the function, purpose of the code and many others.
We can comment either a single line or multiple line.

  • Single Line Comment - Starts with //
  • Multi Line Comment - Starts with /* and ends with */
example

<!DOCTYPE html>
<html>
<head>
    <title>javaScript Comment</title>
</head>
<body>
    <h1>JavaScript Comment</h1>
    <script>
        var number = 23;
       // var Number = 45; Single line Comment
        var NumBer = 67;
        document.write(number);
        /* Multilie Comment
        document.write(Number);
        document.write(NumBer); */ 
    </script>
</body>
</html>



Semicolon
In JavaScript, statements are generally followed by semicolon, which indicates the termination of the statement. However, it is not necessary to use the semicolon at the end of the statement.
example

<!DOCTYPE html>
<html>
<head>
    <title>javaScript Optional Semicolon</title>
</head>
<body>
    <h1>JavaScript Optional Semicolon</h1>
    <script>
        var number = 23;
        var Number = 45
        var NumBer = 67;
        document.write(number + "<br />");
        document.write(Number + "<br />")
        document.write(NumBer + "<br />")
    </script>
</body>
</html>


White Spaces and Line Breaks
The Javascript interpreter ignores tabs, spaces and new lines that appear in the program, except string and regular expression.

example

<!DOCTYPE html>
<html>
<head>
    <title>javaScript Line Breaks and White Space</title>
</head>
<body>
    <h1>JavaScript Line Breaks and White Space</h1>
    <script>
        var number = 23; var Number = 45; var NumBer = 67;
        document.write(number + "<br />");document.write(Number + "<br />");document.write(NumBer + "<br />");
    </script>
</body>
</html>


0 comments:

Post a Comment