Вопрос по javascript, language-design – Javascript очевидное безумие [дубликат]

8

Possible Duplicate:
Conflicting boolean values of an empty JavaScript array

Error: User Rate Limit Exceeded

[ ([] == false), ([] ? 1 : 2) ]

Error: User Rate Limit Exceeded[true, 1]?

Error: User Rate Limit Exceededfalse.

Error: User Rate Limit Exceeded===Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

Edit

Error: User Rate Limit Exceeded[]==falseError: User Rate Limit Exceeded[]Error: User Rate Limit ExceededNaNError: User Rate Limit Exceeded({}) == falseError: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

stackoverflow.com/questions/5491605/… user1150525
Error: User Rate Limit Exceeded![].toString() == falseError: User Rate Limit Exceededfalse. user1150525
![] == falseError: User Rate Limit ExceededtrueError: User Rate Limit Exceeded Elliot Bonneville
forums.whirlpool.net.au/archive/966449#r15310322 user1150525
Error: User Rate Limit Exceeded dmp

Ваш Ответ

2   ответа
9

== false.

false, 0, "", null, undefinedNaNif

Error: User Rate Limit Exceededdeveloper.mozilla.org/en/JavaScript/Reference/Operators/…Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded===Error: User Rate Limit Exceeded==Error: User Rate Limit Exceeded==Error: User Rate Limit Exceeded[]Error: User Rate Limit Exceeded''Error: User Rate Limit Exceeded''Error: User Rate Limit Exceeded''Error: User Rate Limit Exceeded===Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded[] == falseError: User Rate Limit Exceeded[].toString() == falseError: User Rate Limit Exceeded'' == false.
Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded[] === ""Error: User Rate Limit Exceeded[]Error: User Rate Limit Exceeded[].toString()Error: User Rate Limit Exceeded[] == falseError: User Rate Limit Exceeded[].toString == false
8

.

[] ? 1 : 2

11.12 Conditional Operator ( ? : )

Let lref be the result of evaluating LogicalORExpression. If ToBoolean(GetValue(lref)) is true, then Let trueRef be the result of evaluating the first AssignmentExpression. Return GetValue(trueRef). Else Let falseRef be the result of evaluating the second AssignmentExpression. Return GetValue(falseRef)

9.2 ToBoolean

Undefined: false Null: false Boolean: The result equals the input argument (no conversion). Number: The result is false if the argument is +0, 0, or NaN; otherwise the result is true. String: The result is false if the argument is the empty String (its length is zero); otherwise the result is true. Object: true

11.9.3: The Abstract Equality Comparison Algorithm

If Type(y) is Boolean, return the result of the comparison x == ToNumber(y)

9.3 ToNumber

The result is +0 if the argument is false.

11.9.3: The Abstract Equality Comparison Algorithm

If Type(x) is Object and Type(y) is either String or Number, return the result of the comparison ToPrimitive(x) == y.

9.1 ToPrimitive

Return a default value for the Object. The default value of an object is retrieved by calling the [[DefaultValue]] internal method of the object, passing the optional hint PreferredType. The behaviour of the [[DefaultValue]] internal method is defined by this specification for all native ECMAScript objects in 8.12.8.

8.12.8 DefaultValue:

When the [[DefaultValue]] internal method of O is called with no hint, then it behaves as if the hint were Number

Let valueOf be the result of calling the [[Get]] internal method of object O with argument "valueOf". If IsCallable(valueOf) is true then, Let val be the result of calling the [[Call]] internal method of valueOf, with O as the this value and an empty argument list. If val is a primitive value, return val Let toString be the result of calling the [[Get]] internal method of object O with argument "toString". If IsCallable(toString) is true then, Let str be the result of calling the [[Call]] internal method of toString, with O as the this value and an empty argument list. If str is a primitive value, return str.

11.9.3: The Abstract Equality Comparison Algorithm

If Type(x) is String and Type(y) is Number, return the result of the comparison ToNumber(x) == y

9.3.1 ToNumber Applied to the String Type

A StringNumericLiteral that is empty or contains only white space is converted to +0.

11.9.3: The Abstract Equality Comparison Algorithm

If x is the same Number value as y, return true

Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded
Error: User Rate Limit Exceededforums.whirlpool.net.au/archive/966449#r15310322Error: User Rate Limit Exceeded

Похожие вопросы