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
if
is a conditional statementif
is a keyword- In a
if
else
-if
chain, JavaScript JavaScript does not check furtherif
conditions as the firstif
conditions becometrue
. if
whentrue
, executes immediate next statement or block of sttements.