if … else

if … else

Description

if (mixed expression) … else

Parameters

Name Description Type Default Optional
expression The expression to evaluate. mixed No

Examples

Example #1 – if … else example
var x = 2; if (x === 1) { console.log('x is 1'); // Do something. } else if (x === 2) { console.log('x is 2'); // Do something. } else { console.log('x is not 1 or 2'); // Do something else. }

External references