[webkit-dev] Preferred style for checking for undefined in our built-in JavaScript code?

Chris Aljoudi chris at chrismatic.io
Mon Nov 30 12:08:58 PST 2015


FWIW, performance seems to be equivalent:
http://jsperf.com/typeof-vs-undefined-check/39

Chris
https://chrismatic.io/

> On Nov 30, 2015, at 1:01 PM, Geoffrey Garen <ggaren at apple.com> wrote:
>
> For the time being, I like “x === undefined”.
>
> Long term, I’d like us to switch to “x === @undefined”.
>
> We use @ to indicate reserved words in built-ins. Currently, “@undefined" does not exist, but the built-in compiler magically transforms “undefined” a safe reserved word.
>
> The typeof and void 0 code should be fast, but I find it obtuse.
>
> Geoff
>
>> On Nov 30, 2015, at 11:39 AM, Filip Pizlo <fpizlo at apple.com> wrote:
>>
>> I’ve also been guilty of:
>>
>>    if (xxx === void 0)
>>
>> This is slightly better than saying “undefined”, since that’s not actually a reserved word.
>>
>> I believe that all of these should perform the same.  We should pick one based on what looks nicest and what has the most clear semantics.
>>
>> -Filip
>>
>>
>>
>>> On Nov 30, 2015, at 11:37 AM, Darin Adler <darin at apple.com> wrote:
>>>
>>> I see the following in some code:
>>>
>>>  if (xxx === undefined)
>>>
>>> And I see the following in some other code:
>>>
>>>  if (typeof xxx == “undefined”)
>>>
>>>  or
>>>
>>>  if (typeof xxx === “undefined”)
>>>
>>> Is one preferred over the other, style-wise? Is one more efficient than the other?
>>>
>>> — Darin
>>> _______________________________________________
>>> webkit-dev mailing list
>>> webkit-dev at lists.webkit.org
>>> https://lists.webkit.org/mailman/listinfo/webkit-dev
>>
>> _______________________________________________
>> webkit-dev mailing list
>> webkit-dev at lists.webkit.org
>> https://lists.webkit.org/mailman/listinfo/webkit-dev
>
> _______________________________________________
> webkit-dev mailing list
> webkit-dev at lists.webkit.org
> https://lists.webkit.org/mailman/listinfo/webkit-dev


More information about the webkit-dev mailing list