Function Declaration

Functions are an important part of programming. They allow you to write a block of code that you can call over and over again, without having to rewrite it each time.

A function declaration is when you define a function using the function keyword. Here is an example:

Loading Code . . .

In this example, we are defining a function called sayHello that, when called, will log the message 'Hello!' to the console. To call this function, you simply need to write its name followed by parentheses, like this: sayHello()

The parentheses are important, because they tell the computer that you are calling the function, and not just writing its name.

Now you can call this function as many times as you want, and it will always log the same message to the console.

So, imagine all the possibilities! You can write some commands, and then wrap them in a function, and then call that function whenever you want to run those commands. This is a very powerful concept, and it will be used all the time in the rest of your programming journey.

Code time!

In the code below you will find a console.log() statement. Wrap it in a function called sayHello.

Loading...
Loading...
Loading...

© 2024 - ®Mewters