2
1

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 ES6

2
Posted at

JavaScriptで何ができる?

javascriptを使えば、
ウェブコンテンツに動きを入れることができます。(写真の自動切り替えなど)

コードを書くときに気をつけること

・変数

let 変数名;
変数名は、基本的に自由に決められますが、
数字始まりやローマ字、日本語にするのはやめましょう。

・変数の更新

変数は更新することができますが、
その際は頭にletは不要です。

・定数

const 変数名
定数は変数のようなものですが、
更新することができません。

・テンプレートリテラル

文字列や定数の連結は+を用いることでも可能ですが、
それ以外にも方法があります。

文字列の中に${定数}を埋め込めば良いだけですが、
その際、文字列をバッククォーテーションで囲む必要があります。

・コンストラクタ

コンストラクタとは、
new演算子を使って、インスタンスを実装する関数のことです。

インスタンスとは?

そもそもオブジェクト指向のプログラムは、
用意されたオブジェクトをそのまま使うのではなく、
オブジェクト本体からコピーして(インスタンス化して)使っています。
*このインスタンス化の役割を担っているのがnew演算子です。

・this

thisとは、
JavaScriptに元から用意されている
変数のことです。

呼び出した場所や方法によって、
中身が変化する特殊な変数です。

例)
コンストラクタでインスタンスを生成する際、
インスタンスのプロパティをthisで作成する。

function Human(name, age){
  this.name= name;
  this.age=  age;
}

var taro =new Human('太郎', 30);
console.log( taro );

実行結果

Human{name;"太郎", age: 30}

参考

・new演算子
https://www.sejuku.net/blog/24383
https://qiita.com/rindarinda5/items/5501a01bd6001fafcbf7

・this
https://qiita.com/takeharu/items/9935ce476a17d6258e27

2
1
1

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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?