performance - Speed of comparing to null vs undefined in JavaScript -
I have just run a very simple JavaScript (why not ask) test declares a variable, but nothing is assigned to it Does:
This again compares the comparison of the variable variable I was expecting to compare with The results described above come from running tests in Chrome (version 13). Running them in Firefox produces too many results (compared to So, my question is, what could be the reason? Why does Chrome look too much to compare with For quick reference, here is a screenshot of the results: However, when you are examining against If you really need to see if something is undefined, you should use Try it ... and set something on However, if you try and undefine it, then this error will not occur. It is not that you can override The similarity between the only real empty and undefined is that both of them can be included in boolean false. var x; null , and undefined , in other words: var y = (x == null); and var y = (x == undefined); undefined for fasting. Actually it was somewhere. The comparison with null was fastest, about 80% faster. undefined in comparison to null , but it is very minor). null ?
null is a reserved keyword that overrides So, when you're comparing it with Null, you only have to make a comparison undefined So the engine should do a type of lookup and then one Lana, which means that this is actually a bit more demanding.
(if not set == "undefined" ) {}
proof
null in your Javascript console.
cord = "error"; // errors with - & gt; Reference error: Invalid assignment on the left undefined , because you can not do it, but this is undefined is its own old type.
Comments
Post a Comment