JavaScript AND Assignment

01.03.2015

The && operator takes the rightmost “truthy” value or the first “falsy” value.

Example

var result = true && false;

-> false

var result = false && true;

-> false

var result = true && true;

-> true

The && operator can be used in contingent assignment.

Example

var result = true && function(){ return "foo"; }();

-> foo

var result = false && function(){ return "foo"; }();

-> false