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学習の記録

Posted at

はじめに

先週からJavaScriptの学習に入りました.新たに学んだことを箇条書きでアウトプットしていきます.

JavaScript学習内容

  • const変数は,上書きも再宣言もできないが,中身がオブジェクトや配列の場合は,プロパティ・要素の書き換えや追加が可能.
  • 分割代入」を使うことで,オブジェクトのプロパティや配列の要素を取り出す際に,記述量を少なくすることができる.
const myprofile = {name:"taro", age:30};
const {name ,age} = myprofile; /**分割代入を使用*/
const message = `名前は${name}です.年齢は${age}です`;
console.log(message);

実行結果

名前はtaroです.年齢は30です

毎回,オブジェクト.プロパティという書き方をしなくて済むようになる.

  • デフォルト値*」は,undefinedと出力されるのを防ぐために,引数が渡されなかった時に表示させるようにする値.
const myprofile{age:31};
const {age, name="guest"}=myprofile; /**デフォルト値の設定*/
console.log(age);
console.log(name);

実行結果

31
guest

引数nameにデフォルト値guestを設定したことで,undefinedではなくguestが出力されている.

VSCodeでJavaScript単体で実行させるために

JavaScriptはブラウザ上で動作するプログラミング言語のため,通常は単体で実行することができない(HTMLなどとセットになる).
そこで「Node.js」という,JavaScriptを実行するためのアプリケーション(実行環境)をインストールすることで,VSCode上でJavaScript単体で実行できるようになる.

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?