javascript - Data of type undefined has no value? -


in javascript, type "undefined" supposed have 1 value "undefined". however, in example below, undeclared xxx has type "undefined" apparently has no value of kind. not make difference js throws exception because of no value in xxx. consistent js should throw exception on typeof xxx. otherwise, have big hole in logic here.

<!doctype html> <html> <body>  <script> document.write("type=" + typeof xxx); document.write(", value="); document.write(xxx); </script>  </body> </html>  

you need first at:


in example never declare xxx variable, therefore when document.write(xxx) variable xxx doesn't exist.

var xxx; document.write("type=" + typeof xxx); document.write(", value="); document.write(xxx); 

declaring var xxx; no value instantiate , since has no value assigned, default assignment undefined stated in data types.


Comments

Popular posts from this blog

javascript - Hide toolbar of pdf file opened inside iframe using firefox -

Copy range with conditional formatting -

Ansible - ERROR! the field 'hosts' is required but was not set -