Page 71 - Trackpad_V1_Book 8_Flipbook
P. 71

STATEMENTS IN JAVASCRIPT


                 Commands  and instructions  given to  the
                 JavaScript interpreter to take some actions
                                                                                Subject: The confirm( ) Method
                 are called  statements and a collection  of
                                                                                The confirm() method displays a dialog
                 statements is called a script or a program.                    box  with  a  specified  message,  along
                 Within  almost  every browser resides                          with an OK and a Cancel button.
                 the  JavaScript  interpreter.  We  use  the
                 semicolon to terminate a statement but, if
                 the statements are written in separate lines, then the semicolon can be omitted.

                 JavaScript statements consist of keywords, variables, operators, expressions and comments.
                 Let us learn about them in detail.

                 KEYWORDS

                 A keyword is a reserved word that has a special meaning for the JavaScript interpreter. Some of
                 the keywords of JavaScript are:

                                         var,  switch,  let,  for, const,  function,  if,  return, etc.

                 VARIABLES

                 A variable is the name of storage location. It stores a value that can be modified later. JavaScript
                 is a loosely typed language which means it does not require a data type to be declared before
                 using it. Syntax to declare a variable in JavaScript is:

                 var <variable name> = <value>;
                 where var is a keyword, <variable name> is a valid name for the variable and <value> is the value

                 that you want to assign to the variable.
                 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
                 Some of the naming conventions that need to be followed while declaring variables in JavaScript are:

                      Variable names are case-sensitive which means that the variable name 'AGE' is different
                     from 'age'.

                      A variable name must not start with digits 0–9.
                      Variable names can contain letters, digits, or the symbols $ and _.
                      A variable name cannot be a reserved keyword.




                                                                                      Dynamic Web Pages in HTML5  69
   66   67   68   69   70   71   72   73   74   75   76