wrt chapter https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/es6/write-concise-object-literal-declarations-using-simple-fields and coming from Java background, it is super confusing with flexible ways of defining function in JS
Way 1
const getMousePosition = (x, y) => ({ x, y });
Note parenthesis against the function body
Way 2
const createPerson = (name, age, gender) => {
"use strict";
// change code below this line
return {
name,
age,
gender
};
// change code above this line
};
console.log(createPerson("Zodiac Hasbro", 56, "male")); // returns a proper object
No parenthesis in this case.
- Please clarify when to use ( ) and when not to use it ?
- Can I use ( ) in 2nd case ?
Thanks,
Vikram