Lesson 1, Topic 1
In Progress

Using functions

๐Ÿ’ก Once a JS function is defined (declared), you can use it by referencing its name with parentheses ( ) right after.

Note that a function doesnโ€™t have to have parameters – they can simply be left blank in the parentheses.

Code Example

 function greetThePlanet() {
       return "Hello world!";
}

Output

 "Hello world!"

In the above example,there can be zero, one, or multiple arguments in a function, the function “greetThePlanet” simply returns the phrase “Hello World!”, and it doesn’t require any parameters (arguments) in order to do so.


๐Ÿ’ก If a function does have parameters, youโ€™ll need to provide values inside the parentheses when using the function.

Code Example

function square(number) {
       return number * number;
}
square(16);

Output

256

In the above example, you have to provide a number inside of the parentheses in order to the function works and receives a proper output. Otherwise, your code will not work and youโ€™ll get an error message.