Arrow Syntax for Javascript

Hello! No matter how hard I try I can’t seem to understand arrow syntax. When do I use it? How do I know I should add curly braces and when shouldn’t I? When writing arrow syntax why is the beginning () empty?

EX: cancelBtn.addEventListener(“click”, () => confirmCloseDialog.close());

Please help!

In modern JavaScript code, arrow functions are preferred.

It’s the same as when you’re writing an if statement. Any time you have more than 1 line of logic in the function body, you need the curly braces.

That’s only the case for functions that take no arguments.

Although note that when you omit the {} in a return function, you are essentially appending “return” onto the code. The name “return function” is the hint that it returns something. This why it’s also called “implicit return” in many of the instructions.