-
Notifications
You must be signed in to change notification settings - Fork 8.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
javascript-questions#98 & error answer #220
Comments
Yep! The correct code is: const getList = ([x, ...y]) => [x, y]
const getUser = user => {{ name: user.name, age: user.age }}
const list = [1, 2, 3, 4]
const user = { name: "Lydia", age: 21 }
console.log(getList(list))
console.log(getUser(user)) |
Signed-off-by: Alexander Ivanov <oshli.a.er@gmail.com>
the right ways
const getList = ([x, ...y]) => [x, y];
const getUser = user => {return { name: user.name, age: user.age };};
const list = [1, 2, 3, 4];
const user = { name: "Lydia", age: 21 };
console.log(getList(list));
console.log(getUser(user));
// [1, Array(3)]
// {name: "Lydia", age: 21}
const getList = ([x, ...y]) => [x, y];
const getUser = user => ({ name: user.name, age: user.age });
const list = [1, 2, 3, 4];
const user = { name: "Lydia", age: 21 };
console.log(getList(list));
console.log(getUser(user));
// [1, Array(3)]
// {name: "Lydia", age: 21} refshttps://mariusschulz.com/articles/returning-object-literals-from-arrow-functions-in-javascript |
It seems it's not valid at all => { name: user.name, age: user.age } But this is fine => { name: user.name } |
Thank you! Could you please open a PR with the change, I can merge it asap. |
Just to be clear, this is the right solution (which is present in the provided answer): const getUser = user => ({ name: user.name, age: user.age }); But this is not the solution to fix this answer! It clearly teaches us to use @oshliaer This is not fine => { name: user.name } It isn't the result you are looking for, you are defining |
javascript-questions#98 & error answer
https://github.com/lydiahallie/javascript-questions#98-whats-the-output
The text was updated successfully, but these errors were encountered: