I have attached jsfiddle example here. I want to know difference between null and blank
My function is working fine but when I change blank to null in if condition it stop working.
I have attached jsfiddle example here. I want to know difference between null and blank
My function is working fine but when I change blank to null in if condition it stop working.
Share Improve this question edited Aug 30, 2012 at 7:09 sp00m 48.9k31 gold badges150 silver badges259 bronze badges asked Aug 30, 2012 at 7:05 JitenderJitender 7,98932 gold badges116 silver badges218 bronze badges 5-
1
Blank (i.e.
""
) = value (but an empty one),null
= no value at all. – sp00m Commented Aug 30, 2012 at 7:07 -
If you test it:
'' != null
. – Blender Commented Aug 30, 2012 at 7:09 - since i have no value in first input why null is not working – Jitender Commented Aug 30, 2012 at 7:09
-
@amit You do have a value, just an empty one. More obvious is the difference between
0
and null, one is an actual value0
and null is "I have no value". You can add a number to0
but you can't add a value tono value
. – Joachim Isaksson Commented Aug 30, 2012 at 7:10 - @Joachim:so when should i use null in function – Jitender Commented Aug 30, 2012 at 7:12
3 Answers
Reset to default 3You have to pay attention to what ""
, null
, and undefined
, mean in javascript. It can lead to some misconception in boolean tests concerning values and types.
""
is the empty string which is used also as an empty property. A string object "" is defined and is not null.
null
is an object whose type is null. An object is said to be null when it has no other value/property (its type is null).
undefined
means that the object is not defined and the interpreter has no reference to it. undefined is not an object.
Some problems arises when you try to pare those values with false
. Try to have a look at the following examples.
Here are some reference links:
Tutorial on some type checking
A little more explanation
you should probably change the condition to
if('input[type=radio]:checked').val())
this way it will check both null and empty strings. but in this case i dont think you will ever get a null string.dont use
"!="
here because that might lead to some unpredictable behaviour use"!=="
.- null probably is like a null pointer when the object actually points to nothing
- where as empty string points to an object which is
""
A NULL value represents the absence of a value for a record in a field.
An empty value is a value with no significant data in it.
Why an "empty character string" is different from a null value? Cause you're paring a string (with no characters inside) with a with a no data type value: they differ !
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745080942a4610119.html
评论列表(0条)