→
RangeError オブジェクトは、値が配列内に存在しない、または値が許容範囲にない場合のエラーを表します。
¶省く
//コンソールにて function check(n) { if( !(n >= -500 && n <= 500) ) { throw new RangeError("The argument must be between -500 and 500.") } } try { check(2000) } catch(error) { if (error instanceof RangeError) { // Handle the error } }
//コンソールにて function check(value) { if(["apple", "banana", "carrot"].includes(value) === false) { throw new RangeError('The argument must be an "apple", "banana", or "carrot".') } } try { check("cabbage") } catch(error) { if(error instanceof RangeError) { // Handle the error } }