JS_HOME_WORK/68-presence-of-the-function-parameters/solution.js
2025-02-05 08:47:22 +01:00

28 lines
917 B
JavaScript
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/** ЗАДАЧА 68 - Проверка наличия аргументов в вызове функции
*
* Измените функцию "square" так, чтобы в случае ее вызова
* без аргумента генерировалась ошибка
* "Функция "square" не может быть вызвана без аргумента"
*/
function square(a) {
// // OPTION 1
// if (a === undefined) {
// throw new Error('Функция "square" не может быть вызвана без аргумента')
// }
// OPTION 2
if (arguments.length === 0) {
throw new Error('Функция "square" не может быть вызвана без аргумента')
}
console.log(a * a)
}
square(10)
// 100
square()
// ДО: NaN
// ПОСЛЕ: Uncaught Error: Функция "square" не может быть вызвана без аргумента