Code Highlights logo

Learn

Functions

Function Declarations

The syntax for creating a function declaration is as follows:

1function functionName(parameter1, parameter2, ...) {
2 // Code to be executed
3}
  • The keyword function indicates the start of a function declaration.
  • functionName is the name assigned to the function. Choose a descriptive and meaningful name that reflects the purpose of the function.
  • Parameters are enclosed within parentheses ( ). They represent the inputs that can be passed to the function.
  • Curly braces { } contain the block of code to be executed when the function is called.

Instructions

1.

Declare a function named greet with no parameters.

2.

Inside the function body, print the messeage "Hello, John!" to the console.

Sign up to start coding

Already have an account?

Sign In

Course content