Javascript does not implicitly return Boolean values when using Boolean operators:
&&
returns the second element, if both elements equal to true
or the first, if one of them is false
||
returns the first element, if it equals to true
, or the second, if the first matches false
Some examples:
("foo" && "bar") === "bar"
(1 && "foo") === "foo"
(undefined && false) === undefined
(1 || "foo") === 1
(0 || "foo") === "foo"
(undefined || "foo") === "foo"
(undefined || 1) === 1
(undefined || false) === false
Your case from jQuery mobile:
prop && $.mobile.ns + prop
- in this case prop
will be used if prop
AND $.mobile.ns
are equal to true
. If one of them is false
, $.mobile.ns
will be used. I think in this situation it's used when prop === null
which equals an empty string.
You could expand this to:
$.jqmData = function( elem, prop, value ){
if(prop == false)
prop = $.mobile.ns
return $.data( elem, prop + prop, value );
};