JS: if condition | JavaScript

JavaScript if condition

JavaScript if condition is the decision making in the program.

if(true) alert('true part'); else alert('false part') var x = 1, y = 0; if( x > y) alert('x is more than y'); else alert('y is not less than x')

if else-if else

var r = Math.random(); //get random number alert('random number is: ' + r); if(r > 0.5) alert('more than half'); else if( r < 0.5) alert('less than half'); else alert(r + ' is half'); random number is: 0.7272122967453893 more than half
  1. if is a conditional statement
  2. if is a keyword
  3. In a if else-if chain, JavaScript JavaScript does not check further if conditions as the first if conditions become true.
  4. if when true, executes immediate next statement or block of sttements.