javascript - How can I easily set a variable to false with a default of true? -


i set object properties so,

// boolean this.listening = config.listening || true; 

but config.listening either true or false, , in case this.listening true because if config.listening false equal true.

is there better way set these boolean properties without having if statement?

is there if isset function in javascript check exists rather equals to?

you use ternary (conditional) operator this:

this.listening = config.listening === false ? false : true; 

if config.listening false, this.listening set false. if it's other value, it's set true.

if want check if it's defined, use:

this.listening = typeof config.listening !== "undefined" 

references:


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -