Trending News
Home / Web Development / Javascript / 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.

JavaScript code

The script tag takes two important attributes −

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

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

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

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

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.

    // This is a one-line comment

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

    /* 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 (<!—).

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

Javascript Comment Example

Loading Facebook Comments ...
Social Media Auto Publish Powered By :