Progate JS
リモートの会社で有償アカウントもらってやれっていわれてProgateのJS をやっている
U3では関数とアロー関数
const add = (num1,num2,) => { return num1 + num2; }
条件式の関数化,
const check = number => { return number % 3; } if (check) console.log(`It is Multiples of 3`);
引数のdefault, 変数のScope,
const name = 'defName'; const introduce = (name) => { console.log(`I am ${name}`); }; introduce('Sheep'); // output: sheep console.log(`name: ${name}`); // output: defName; introduce(); // output: undef. NOT defname.
3つの値の最大を求める関数の実装
const number1 = 103; const number2 = 72; const number3 = 189; const getMax = (a,b,c) => { if( a < b) if (b < c) return c; if (c < b) return b; if (b < a) if (a < c) return c; if (c < a) return a; } const max = getMax(number1, number2, number3); console.log(`Max num is ${max}`);
U4 OBJ
object(obj)にfuncも入る.
class(cls)の意義はobjの作成の自動化.
class Animal{ constructor() { this.name = 'defName'; this.age = 0; } } const dog = new Animal(); console.log(`${dog.name}, ${dog.age}`);
でclsの作成constructorの設計 dogのAnimal classを使った生成 dogの出力ができる
constructorにargを渡すことでその値でセットできる
constructor(name,age) { this.name = name; // argのnameを使う this.age = 0; }
clsにはconstructorの他にmethod
がある