Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
What is a Function? | Functions
Introduction to JavaScript
course content

Course Content

Introduction to JavaScript

Introduction to JavaScript

1. Basic Concepts
2. Variables and Data Types
3. Basic Operations
4. Conditional Statements
5. Loops
6. Functions

bookWhat is a Function?

Functions are specific objects that receive values, perform operations, and then return values. One of the most significant advantages of a function is its ability to be used multiple times, promoting code reusability.

Let's explore a simple function example:

123456789101112
function meeting(name) { console.log("------ Meeting with " + name + " ------"); console.log("Hello, " + name + "!"); console.log("I'm glad to see you!"); console.log("But I need to go."); console.log("Goodbye, " + name + "!"); console.log("See you again soon!"); } meeting("Mary"); meeting("Kate"); meeting("Sean");
copy

In this example, the meeting function is defined and takes a name parameter. Inside the function is a code block containing various console.log statements. The function is called three times with different names as arguments.

The power of functions lies in their reusability. This function, written in just 8 lines of code, contains a code block of 6 lines. However, it can be called multiple times, eliminating the need to copy and paste those 6 lines of code.

Note

The example here aims to provide a basic understanding of functions. No detailed analysis is needed for now. In practice, functions are versatile and help developers organize and reuse code effectively.

Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 6. Chapter 1
We're sorry to hear that something went wrong. What happened?
some-alt