I
I
IcEWaRRiOr2021-01-18 15:43:24
JavaScript
IcEWaRRiOr, 2021-01-18 15:43:24

Error running console command in Firefox?

I noticed a strange thing in the Firefox console - the first time it executes the command, and all subsequent times it gives an error. I'll give an example:

let age = prompt('Сколько тебе лет?');
alert(`Тебе ${age} лет!`);


The first time it runs without any complaints, and the next time it gives out: And this is exactly in the desktop Firefox (version 84.0.2), in the Chrome console there are no problems with this. Why is that?

Uncaught SyntaxError: redeclaration of let age

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alex, 2021-01-18
@IcEWaRRiOr_2002

Because formally you call something like this

let age = prompt('Сколько тебе лет?');
alert(`Тебе ${age} лет!`);

let age = prompt('Сколько тебе лет?');
alert(`Тебе ${age} лет!`);

The variable age is declared twice within the same context. Which is a mistake. Chromium behaved the same way until recently. Then, he allowed to re-declare variables directly in the console using let / const

E
Evgeny Palych, 2021-01-18
@xzKakoyLogin

Use Console Features varinstead andletlet

let x;
let x; // ошибка: переменная x уже объявлена

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question