Page 335 - Webapplication11_C11_Flipbook
P. 335

For example:

                   var age = 16;
                   var name = "A"
                 We can declare multiple variables in the same line in the following way:

                   var v1 = 1, v2 = 'Delhi', v3;
                 Variable Naming Conventions
                 In JavaScript, variable naming conventions are important to make code more readable and maintainable.
                 Some rules and best practices for naming variables in JavaScript are as follows:

                 Ð ÐCamel Case Notation: JavaScript variables are typically written in camelCase. The first word starts with a lowercase
                   letter, and each subsequent word starts with an uppercase letter.

                   Example:

                   let firstName = "John";
                   let totalAmount = 100;
                 Ð ÐCase Sensitivity: JavaScript variable names are case-sensitive. This means firstName, Firstname, and firstname are
                   all different variables.
                 Ð ÐDescriptive Names: Use meaningful names that describe the value the variable holds or the purpose it serves.

                   let userAge = 25;     // good
                   let x = 25;           // not descriptive
                 Ð ÐAllowed  Characters:  Variable  names  can  include  Letters  (a-z,  A-Z),  Digits  (0-9),  dollar  sign  ($),  underscore  (_).
                   However, variable names cannot start with a digit.
                   Example:

                   let myVar1 = 10;      // valid
                   let 1stVar = 20;      // invalid, starts with a number
                 Ð ÐNo Reserved Keywords: Variable names cannot be JavaScript reserved words. In JavaScript, reserved words (or
                   keywords) are words that have a specific meaning in the language syntax. These words cannot be used as identifiers,
                   such as variable names, function names, or class names, because they are already reserved for specific purposes
                   by the language.
                 abstract      char         double       for          int          private      synchronized  typeof

                 arguments     const        else         function     interface    protected    this         void
                 boolean       continue     eval         goto         long         public       throw        volatile
                 break         debugger     false        if           native       return       throws       while

                 byte          default      final        implements   new          short        transient    var
                 case          delete       finally      in           null         static       true         with
                 catch         do           float        instanceof   package      switch       try          yield


                 Ð ÐConstants  in  Upper  Case:  Variables  that  hold  constant  values  are  often  written  in  UPPERCASE  letters,  with
                   underscores to separate words.
                   Example:

                   const MAX_SPEED = 120;
                   const PI = 3.14159;

                                                                                                  JavaScript Part 1  333
   330   331   332   333   334   335   336   337   338   339   340