Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
学ぶ What Are Functions in JavaScript? | Functions in JavaScript
Introduction to JavaScript

bookWhat Are Functions in JavaScript?

メニューを表示するにはスワイプしてください

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.

question mark

What is the main benefit of using the calculateTotal function below?

正しい答えを選んでください

すべて明確でしたか?

どのように改善できますか?

フィードバックありがとうございます!

セクション 6.  1

AIに質問する

expand

AIに質問する

ChatGPT

何でも質問するか、提案された質問の1つを試してチャットを始めてください

セクション 6.  1
some-alt