Jump to content
Sign in to follow this  
j.silver

Affect of NULL Type in Coding

Recommended Posts

Having NULL type as an object to be a bug in js, is there any harm to code this could result in, and what precautions should we take to avoid such harm?

Share this post


Link to post
Share on other sites

It's not really a bug, it's actually designed that way in the specification: http://www.ecma-international.org/ecma-262/5.1/#sec-11.4.3

 

My first recommendation would be to not use the typeof operator. You might think you need it, but there probably is a better way to design your software. If you show me the code where you need it I can find out how to write the code without it.

Share this post


Link to post
Share on other sites

Null is usually the value you assign to a variable if it's meant to contain an object but does not have one yet. You can set a variable to null in order to remove a reference to an object and free memory.

Share this post


Link to post
Share on other sites

It's no more "dangerous" to use null than it is to use an integer, boolean, or string. It's just a type of value.

Share this post


Link to post
Share on other sites

Having NULL type as an object to be a bug in js, is there any harm to code this could result in, and what precautions should we take to avoid such harm?

 

Null is commonly used to indicate that a variable or object is invalid, so it is not a bug, but it may indeed indicate that your code isn't working.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...