3

I want to write a function that uses argument value. If argument does not exist it will use value true by default.

var check = function(truthValue){
    var val = truthValue || true;
    console.log(val);
};

The problem is that if I pass value false to it,as it will still use default value. So how do I check if varible exists and use that value in Javascript?

sublime
  • 4,013
  • 9
  • 53
  • 92

1 Answers1

7

Use

if (typeof val === 'undefined') val = true;
Denys Séguret
  • 372,613
  • 87
  • 782
  • 758