vendredi 17 juin 2016

Checking null value inside function returns wrong result

I am not sure what's going on here. When I check if variable is null inside the function I get (variable is not null) which is not correct but if I remove the function part and test directly it returns (variable is null) which is correct. What's happening ? why is javascript so confusing ?

var variable = null;

function scoppedVariables(variable) {
  if( variable === null ) {
  console.log('variable is null');
} else {
  console.log('variable is not null');
}

}

scoppedVariables();

Aucun commentaire:

Enregistrer un commentaire