F
F
fapchat2020-04-27 21:46:43
JavaScript
fapchat, 2020-04-27 21:46:43

What happens if you declare a variable in js without the word var, const or let?

Variables declared inside a function without a keyword will become global variables

P/S. The function needs to be called for this
. Is there any other peculiarity in such a declaration of variables, besides the fact that this cannot be done in strict mode?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Igor, 2020-04-27
@fapchat

strict mode only tells the browser to process a particular module/script/function in ES5+ mode.
Prior to ES5, it was allowed that you create a variable without a VAR, then it was added to the global scope (in the browser this is window). The ES5+ standards don't allow this. That is, it will not be possible to simply answer your question. ES5+ will throw an error. And since there were no const and let in the standards before, it is not correct to ask such a question.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question