Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
19
rated 0 times [  22] [ 3]  / answers: 1 / hits: 137205  / 13 Years ago, sun, january 1, 2012, 12:00:00

in javascript,



var a = '';
var b = (a) ? true : false;


var b will be set to false.



is this a defined behavior that can be relied upon?


More From » string

 Answers
2

Yes. Javascript is a dialect of ECMAScript, and ECMAScript language specification clearly defines this behavior:



ToBoolean


The result is false if the argument is the empty String (its length is zero);
otherwise the result is true



Quote taken from http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf


[#88290] Friday, December 30, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
lamarmaximiliand

Total Points: 388
Total Questions: 104
Total Answers: 104

Location: Oman
Member since Fri, Dec 23, 2022
1 Year ago
;