mardi 26 avril 2016

AnuglarJs best practice to check if undefined and null

I would like to know which way to check if a var is null or undefined in angularjs is the best way.

First way :

if(!myVar){...}

Second way :

if(myVar === null || myVar === undefined){...}

Third way :

if(angular.isUndefined(myVar) || myVar === null){...}

I prefere the first one but I want to be sure if it's the best way. The problem with the last one is that I use an angular's function to test if it's undefined and a native JavaScript's way to check if it's null.

Thanks everyone !

Aucun commentaire:

Enregistrer un commentaire