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 1 year has passed since last update.

JavaScript: 関数(function、メソッド)の書き方

Last updated at Posted at 2021-05-20

処理内容を一度定義しておいて、別の場所から呼び出す(実行する)方法です。

function hello() {
  document.write("hello, I like codes.");
}

上記が関数の定義。
下記のものを書くと、呼び出して実行されます。

hello(); //実行。

例:

<script>
  function hello() {
  document.write("hello, I like codes.");
}
hello(); //実行。
</script>

console出力で確認する場合:

<script>
  var testMes = "I love codes";
console.log ('testMes=' + testMes);
</script>

変数に入れて実行する場合の例:

<script>
var helloTest =  function hello() {
  document.write("hello, I like codes.");
}
helloTest(); //実行。
</script>
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?