JS_HOME_WORK/27-const/finish.js
2025-01-17 01:00:07 +01:00

24 lines
697 B
JavaScript
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.

/** ЗАДАЧА 27 - Const
*
* Ответьте на следующие вопросы:
* 1. Почему после 13 строки не выдается ошибка?
* 2. Почему после строки 18 генерируется TypeError?
*
* Измените одну строку кода, чтобы эта ошибка исчезла.
* Не меняйте строки 13, 18
*/
const arr = [1, 2] // <-- Объявление переменной используя const
arr.push(3)
console.log(arr)
// [1, 2, 3]
arr = [1, 2, 3, 4]
// ДО: Uncaught TypeError: Assignment to constant variable.
// ПОСЛЕ: Нет ошибки
console.log(arr)
// [1, 2, 3, 4]