#引数の初期値設定
function myfunc(price, tax = 0.1){
const result = price + price * tax;
return result;
}
myfunc(10); //11
myfunc(10, 0.08); //10.8
#複数の引数を渡す
function myfunc(...numbers){
let result = 0;
for(const number of numbers){
result += number;
}
return result;
}
#反復処理のスキップ
//奇数だけ表示
for(let i = 0; i <10; i++){
if(i % 2 === 0){
continue;
}
console.log(i);
}
#文字列のトリミング
const string1 = ' hello ';
string.trim(); //hello
#文字列の操作
//文字列の検索
const mystring = 'javascript';
const string1 = mystring.indexOf('script'); //4
const string2 = mystring.indexOf('java'); //0
const string3 = mystring.lastIndex('a'); //3
const string4 = mystring.indexOf('html'); //-1
const string5 = mystging.search('script') //4
mystring.includes('script'); //true
mystring.startsWith('java'); //true
mystring.endsWith('script'); //true
//文字列を取り出す
mystring.slice(0,4); //java
mystring.slice(0); //javascript
mystring.substr(4,6); //script
//文字列の置き換え
const imageName = 'image1.png';
imageName.replace('1.png','2.png'); //images2.png
let phoneNumber = '080-1234-5678';
phoneNumber.replace('-', '');//0801234-5678
phoneNumber.replace(/-/g, '');//08012345678