Sunday, 24 July 2016

JavaScript Identifiers

Identifiers
It is the names given to all the components, like variables, methods.
ECMAScript has defined some rules for identifiers.

  • Identifier must start with a letter, dollar sign ($), or underscore (_).
  • Identifier cannot start with a number.
  • Identifier can contain any combination of letters, a dollar sign, underscore and numbers after the first character.
  • Identifier can be of any length.
  • Identifier are case-sensitive, for example number and Number are different identifier.
  • Identifier cannot contain reserved world or keywords.
example

<!DOCTYPE html>
<html>
<head>
    <title>javaScript Identifier</title>
</head>
<body>
    <h1>JavaScript Identifier</h1>
    <script>
        var numberLiteral = 23;
        var _floatingpointLiteral = 45.908;
        var $_booleanLiteral = true;
        var $string_Literal = "This is a String";
        var _arrayLiteral = ["array literal 1", "array literal 2", "array literal 3"];
       
        document.write(numberLiteral + "<br />");
        document.write(_floatingpointLiteral + "<br />");
        document.write($_booleanLiteral + "<br />");
        document.write($string_Literal + "<br />");
        document.write(_arrayLiteral[0] + "<br />");
        document.write(_arrayLiteral[1] + "<br />");
        document.write(_arrayLiteral[2] + "<br />");
    </script>
</body>
</html>


0 comments:

Post a Comment