undefinedfix
Sign in

Can you pass an obj into a function?

lukasm1 edited in Fri, 12 Aug 2022

such as

function(a,b) {
    return a + b;
}
let obj = {a:1,b:2};
function(obj);

I've seen this kind of writing before, but I'll have problems with it. Cannot output 3 correctly.

2 Replies
rortr
commented on Fri, 12 Aug 2022

What you want may be:

let fnc = function({a,b}) {
    return a + b;
}
let obj = {a:1,b:2};
fnc(obj);
abalfazl9776
commented on Sat, 13 Aug 2022

You're talking about the deconstruction of ES6?? http://es6.ruanyifeng.com/#do...