DEV Community

loading...

Discussion on: What is {x:1} and why does it return 1 🤷‍♂️

Collapse
jcubic profile image
Jakub T. Jankiewicz • Edited

You may think that this actually doesn't matter much, because it never happen in real code, but this is really important for arrow functions:

const fn = () => {x: 1};
Enter fullscreen mode Exit fullscreen mode

this is a function that return undefined not object, because it's block with label and no return.

Collapse
patarapolw profile image
Pacharapol Withayasakpunt

Good linters will tell.

Collapse
jcubic profile image
Jakub T. Jankiewicz

This is what ESLint will tell you, you got errors but you may have no clue what they mean:

  5922:39  error  'x:' is defined but never used                    no-unused-labels
  5922:39  error  This line has 2 statements. Maximum allowed is 1  max-statements-per-line
  5922:42  error  Missing semicolon                                 semi
Enter fullscreen mode Exit fullscreen mode
Collapse
h43z profile image
h43z Author

ohhh... good to know. Thank you!