JS_HOME_WORK/67-default-parameters/start.js
2025-02-05 08:47:22 +01:00

27 lines
657 B
JavaScript
Executable File
Raw Permalink 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.

/** ЗАДАЧА 67 - Параметры функции по умолчанию
*
* 1. Ответьте на следующий вопрос:
* - Почему в строке 12 мы не можем просто использовать оператор ИЛИ?
* mult = mult || 2
*
* 2. Перепишите функцию с использованием значения по умолчанию
* для параметра mult в "multiplyBy"
*/
function multiplyBy(a, mult) {
mult = mult !== undefined ? mult : 2
console.log(a * mult)
}
multiplyBy(2)
// 4
multiplyBy(2, undefined)
// 4
multiplyBy(2, 0)
// 0
multiplyBy(5, 10)
// 50