Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does var {u,v,w} = x; mean in Javascript? [duplicate]

I have seen this in a piece of JS code:

var {status, headers, body} = res;

What does it do?

like image 919
jd. Avatar asked Mar 04 '11 06:03

jd.


2 Answers

nice method to set few variables at once from an object (open firebug and paste this to console)

var status=4;
var headers=4;
var body=4;

var res = {status:1, headers:2, body:3};
window.alert(status);
var {status, headers, body} = res;
window.alert(status);
like image 191
fazo Avatar answered Sep 29 '22 10:09

fazo


i read something different from your expression here . this may help u

 var { a:x, b:y } = { a:7, b:8 };
 Print(x); // prints: 7
 Print(y); // prints: 8
like image 36
diEcho Avatar answered Sep 29 '22 08:09

diEcho