LoginSignup
1
0

More than 5 years have passed since last update.

[Progate学習memo] JavaScript Ⅰ~Ⅳ

Last updated at Posted at 2018-04-03

Progateは月額980円(税込み)でプログラミングを学べるサービス (無料会員でも一部サービスを利用できる。)
Progate レッスン一覧

JavaScript

デバック

console.log("  ");
console.log("Hello,World!");
console.log("Hello,"+"World!");
console.log(3+5);
console.log("3"+"5");

結果

Hello,World!
Hello,World!
8
35

変数宣言

var 変数名 = ;
var name="Raara";
var age=11;

条件分岐

比較演算子

論理式 a=b a≠b a<b a≦b a>b a≧b
JS a===b a!==b a<b a<=b a>b a>=b

※ JavaScriptでは、 等号は a===b 不等号は a!==b

複数条件式

// かつ
条件式1 && 条件式2

// または
条件式1 || 条件式2

if文

if(条件式1){
    処理a
}else if(条件式2){
    処理b
}else{
    処理c
}

switch文

switch(対象){
    case 値1:
        処理a
        break;
    case 値2:
        処理b
        break;
    default:
        処理c
}

ループ

for文


for(変数の定義; 条件式; 変数の更新){
    処理
}

for(var i=0; i<=2; i++){
    console.log(i);
}

結果

0
1
2

while文


while(条件式){
    処理
}

var i=0;
while(i<=2){
    console.log(i);
    i++;
}

結果

0
1
2

配列

配列の操作


var 配列=[値1, 値2];

var soramiSmile=["Raara", "Mirei", "Sophie"];
console.log(soramiSmile[0]);

// 要素数(lengthメソッド)
console.log(soramiSmile.length);

// 要素の更新
soramiSmile[0]="Non";
console.log(soramiSmile);

結果

Raara
3
["Non", "Mirei", "Sophie"]

追加(pushメソッド)


配列.push(追加したい要素);

var aromagedon=["Mikan", "Aroma"];
aromagedon.push("Gaaruru");
console.log(aromagedon);

結果

["Mikan", "Aroma", "Gaaruru"]

連想配列(辞書?)


var 連想配列={キー1値1, キー2値2};

var godIdol={"name":"Raara", "color":"purple"};
console.log(godIdol.name);
console.log(godIdol["color"]);

結果

Raara
purple

関数


function 関数名(引数){
    実行処理
}

戻り値


function add(a, b){
    return a+b;
    console.log("計算が終わりました"); // returnの後ろ呼び出されない
}
add(3,5);

結果

8

記事の制作者:
https://twitter.com/amber_seia

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