Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
学ぶ Functions | Section
JavaScript Essentials for React Native Development

bookFunctions

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

A function in JavaScript is a reusable block of code that performs a specific task. You define a function using the function keyword, followed by a name, a list of parameters inside parentheses, and a block of code called the function body inside curly braces.

12345678
// Function declaration function greet(name) { return "Hello, " + name + "!"; } // Calling the function const message = greet("Sam"); console.log(message); // Output: Hello, Sam!
copy

The parameters are placeholders for values you provide when calling the function. In the example above, name is a parameter. The function body contains the code that runs when the function is called. Inside the body, you can use a return statement to send a value back to the place where the function was called. If you do not include a return statement, the function returns undefined by default.

When you call a function, you provide arguments, which are the actual values for the parameters. In the code sample, the function greet is called with the argument "Sam". The function returns the string "Hello, Sam!", which is stored in the variable message and then printed to the console.

question mark

What does a function do?

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

すべて明確でしたか?

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

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

セクション 1.  4

AIに質問する

expand

AIに質問する

ChatGPT

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

セクション 1.  4
some-alt