Javascript-Syntax

Hi all,
JavaScript syntax is the set of rules.JavaScript can be implemented using JavaScript statements in webpages that are placed within the <script>……..</script> HTML tags.You can place the <script&gt tags anywhere within your web page. but it is normally recommended that you should keep it within the <head> tags.




A simple syntax of your JavaScript will appear as follows.

<script>
JavaScript code
</script>

The script tag takes two important attributes −

  • Language − This attribute specifies what scripting language you are using. Typically, its value will be javascript.
    eg:

    <script language=”javascript”&ht;
    JavaScript code
    </script>

  • Type − This attribute is what is now recommended to indicate the scripting language in use.Its value should be set to “text/javascript”.
    eg:

    <script type=”text/javascript”>
    JavaScript code
    </script>




So your JavaScript segment will look like −


Comments in JavaScript

JavaScript supports both C-style comments and C++-style comments:

  • One-line comments of C++ style. These comments begin with // and continue up to the next line break,and is ignored by JavaScript.
    eg:

    // This is a one-line comment




  • Multiple-line C-style comments. Everything between /* and */ is a comment.
    eg:

    /* This is a comment */
    /* This is first comment
    This is second comment
    This is third comment
    */

  • One-line comments with the HTML comment-opening sequence (<!—).
    eg:

    <!—This is also a one-line JS comment —>M

Javascript Comment Example


Leave a Reply

Your email address will not be published. Required fields are marked *