Posted at

【備忘録】Progate JavaScript 1,2 まとめ


プログラムを実行

console.log("Hello World!");

console.log(1+2);
console.log("1+2");

結果:
Hello World!
3
1+2


文字列の連結

console.log("こんにちは"+"世界");

結果:
こんにちは世界


変数の定義

let name = "Tanaka";

console.log(name);
name = "Suzuki";
console.log(name);

結果:
Tanaka
Suzuki
//letによる変数宣言は後に更新可能
---------------------------------

const name = "Tanaka";
console.log(name);
name = "Suzuki";
console.log(name);

結果:
Tanaka
Tanaka
//constによる変数宣言は後に更新不可


テンプレートリテラル

const name = "Tanaka";

console.log(`My name is ${name}.`);

結果:
My name is Tanaka.

//`文字列${変数}`で「+」と同等の役割


条件分岐

const number = 18

if (number > 10){
console.log('Number is greater than 10.');
}

結果:
Number is greater than 10.
-------------------------------------

const number = 18
if (number > 20){
console.log('Number is greater than 20.');
} else {
console.log('Number is smaller than 20.');
}

結果:
Number is smaller than 20.