( typeof boolParam === 'undefined' ) && ( boolParam = true);

(removed a ;)

On Tue, Oct 25, 2011 at 11:31 PM, Xavier MONTILLET
<[email protected]> wrote:
>> boolParam = (typeof boolParam === 'undefined' ? true : boolParam);
>
> Rather
>
> if ( typeof boolParam === 'undefined' ) {
>    boolParam = true;
> }
>
> Because what you're doing there is
>
> if ( typeof boolParam === 'undefined' ) {
>    boolParam = true;
> } else {
>    boolParam = boolParam;// wtf ?
> }
>
> with the || pattern you do the same thing but you gain way better
> visibility so there is a use.
>
> And if you want a single line :
>
> ( typeof boolParam === 'undefined' ) && ( boolParam = true; );
>
> On Tue, Oct 25, 2011 at 7:48 PM, dmolin <[email protected]> wrote:
>> I would stick to something like:
>>
>> boolParam = (typeof boolParam === 'undefined' ? true : boolParam);
>>
>> On Oct 21, 4:18 pm, HankyPanky <[email protected]> wrote:
>>> I want my function to have one parameter, namely boolParam, which has
>>> a default value of TRUE;
>>> In the first place, it seems that the following snippet will do, but
>>> it's absolutely wrong and boolParam will always set to TRUE even if a
>>> false value is passed to the function;
>>>
>>> What's your solution to this using this pattern?
>>>
>>> funtion myFunc(boolParam) {
>>>        boolParam = boolParam || true;
>>>        /*rest of the code*/
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> }
>>
>> --
>> To view archived discussions from the original JSMentors Mailman list: 
>> http://www.mail-archive.com/[email protected]/
>>
>> To search via a non-Google archive, visit here: 
>> http://www.mail-archive.com/[email protected]/
>>
>> To unsubscribe from this group, send email to
>> [email protected]
>>
>

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/[email protected]/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/[email protected]/

To unsubscribe from this group, send email to
[email protected]

Reply via email to