Javascript: underfined value.
One my colleague was amazed about javascript behavior with undefined:
On my opinion, javascript engine treat undefined as null in most cases.
But it will throw error in case you directly user undefined variable, in case of undefined field - all okay:
But, I am suspect, that the first case was designed to warn a developer that he misspelled variable name.
Undefined type and its tricky behavior - are common part of all script and not-statically-typed languages.
I am even recall my amazed face many years ago about SQL NULL behavior:
undefined == null //trueUndefined behavior is tricky enought.
On my opinion, javascript engine treat undefined as null in most cases.
But it will throw error in case you directly user undefined variable, in case of undefined field - all okay:
alert(ee); //ReferenceError: ee is not defined alert(window.ee); //alert UnderfinedPossible, such behavior is nonsense!
But, I am suspect, that the first case was designed to warn a developer that he misspelled variable name.
Undefined type and its tricky behavior - are common part of all script and not-statically-typed languages.
I am even recall my amazed face many years ago about SQL NULL behavior:
"WHERE name = NULL" -- have different behavior in SQL ISO mode and non-ISO mode. "WHERE name IS NULL" -- this works fine regardless ISO mode.Links:
- http://www.w3schools.com/jsref/jsref_undefined.asp
- https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/undefined
- http://stackoverflow.com/questions/776950/javascript-undefined-undefined
- http://stackoverflow.com/questions/894860/set-a-default-parameter-value-for-a-javascript-function
Comments
Post a Comment