JavaScript if...else Statements


Conditional statements are used to perform different actions based on different conditions. JavaScript has the following conditional statements:
Note that if is written in lowercase letters. Using uppercase letters (IF) will generate an error. The else if and else parts are optional.
 if ( cond1 ) {
   to be executed if cond1 is true
 }
 else if ( cond2 ) {
   to be executed if cond2 is true
 }
 else {
   to be executed if cond1 & cond2 are not true
 }

The script checks the current minute:
  • The method getMinutes of the object Date returns the minutes, between 0 and 59, in the specified date according to local time.

  • The operator new creates an instance of a user-defined object type or of one of the built-in object types that has a constructor function.



   


Demonstration
The following demonstration shows how the script of HTML and JavaScript is displayed on the Web.