Semicolon after curly braces?

In the function review there is picture with a function, where at the end, after curly braces there is semi semicolon.
I thought you dont need to put semicolon after curly braces? Picture <- this one

Yes normally for functions you don’t put a colon. However, arrow functions are function expressions (as opposed to a function declaration).

It’s a bit of a different philosophy about how things work but in a basic way you can consider how normally you might declare a variable:

const x = 5;

so if we use the same format it makes sense to use a semicolon

const myNewFunction = () => { console.log("hello world") };
// this prints "hello world" when myNewFunction() is invoked

In English, we can read the last bit of code left to right thus:

  • Create a new constant named myNewFunction
  • set its value to to a function that takes no parameters (which is why () is empty)
  • the code inside the function is a console.log statement.

Further reading: Imperative vs Declarative Programming – the Difference Explained in Plain English

1 Like

hmm ok, thank you. i think i understood! :+1:

Check out the link, it’s a bit of a complicated topic so don’t worry if it seems like a lot at first.

@kasparspetersons2077 because you might say to yourself (I certainly did…), why have 2 ways to do 1 thing. It’s basically to cover 2 different styles of approaching programming.