var el1,el2 = [1,2] why not?

Jussi Kalliokoski jussi.kalliokoski at gmail.com
Wed Jul 4 10:16:50 PDT 2012


With destructuring (try in Firefox) you can do:
let [param1, param2] = window.location.search.replace('?','').split('&')

And why: because what you're doing is defining param1 to be undefined and
param2 to be the value of that expression, just like var a, b = 1 would
result in a being undefined and b being 1.

Cheers,
Jussi

On Wed, Jul 4, 2012 at 8:08 PM, Hemanth H.M <hemanth.hm at gmail.com> wrote:

> Hello Hackers,
>
> This might be silly, but let the code speak :
>
> var param1,param2 = window.location.search.replace('?','').split('&')
>  undefined
> param1
>  undefined
> param2
>  ["foo=bar", "hello=world"]
> a=1
>  1
> b=2
>  2
> a,b=b,a
>  1
> a
>  1
> b
>  2
>
> Why not param1 be equal to "foo=bar" and param2 be equal to "hello=world"?
>
>
> --
> *'I am what I am because of who we all are'*
> h3manth.com <http://www.h3manth.com>
> *-- Hemanth HM *
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120704/d9c1ab0a/attachment.html>


More information about the es-discuss mailing list