0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

JavaScriptの関数定義と呼び出し

Last updated at Posted at 2019-07-10

#JavaScriptの基本
コピペして使ってください。
ES6を対象としています。

###関数

sample.js
//関数定義
const hello = function(){
  console.log("こんにちは!");
}
//関数の呼び出し
hello();

//アロー関数
const greet = ()=>{
  console.log("こんばんは!");
}
greet();

###引数、戻り値

sample.js
//引数の指定
const add = (number1, number2) => {
  console.log(number1+number2);  
};
add(5,7);

//戻り値の指定
const half = (number) => {
  return number/2;
};
const result = half (130);
console.log(`130の半分は${result}です`);

###オブジェクトと関数

sample.js
//関数を含むオブジェクトの作成
const animal = {
  name: "ポチ",
  greet: ()=>{
    console.log("こんにちは");
  }
}

//プロパティの値、関数の呼び出し
console.log(animal.name);
animal.greet();
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?