j.silver Posted November 1, 2016 Share Posted November 1, 2016 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? Link to comment Share on other sites More sharing options...
Ingolme Posted November 1, 2016 Share Posted November 1, 2016 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. Link to comment Share on other sites More sharing options...
j.silver Posted November 1, 2016 Author Share Posted November 1, 2016 Any precautions or recommendations in using NULL itself? Link to comment Share on other sites More sharing options...
Ingolme Posted November 1, 2016 Share Posted November 1, 2016 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. Link to comment Share on other sites More sharing options...
justsomeguy Posted November 1, 2016 Share Posted November 1, 2016 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. Link to comment Share on other sites More sharing options...
davej Posted November 1, 2016 Share Posted November 1, 2016 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. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now