5 views
Какие сущности относятся к глобальной, функциональной и блочной областям видимости?
Asked at
AI answer
In JavaScript, scope depends on the kind of declaration and the context.
- Global: declarations at the top level of a classic script.
varand function declarations can become properties of the global object;let,const, andclassare available globally in the script, but are not its properties. In an ES module, the top level is the module scope, not the global scope. - Function: parameters and local
vardeclarations inside a function are visible throughout that function.functiondeclarations also have function scope. - Block:
let,const, andclassare visible only inside the nearest{}block; examples include the bodies ofif,for, andwhilestatements.
Unlike let and const, var is not limited to ordinary blocks.
Also asked at IT One
- Have you worked with useLayoutEffect and how does it differ from useEffect?
- What is Event Loop in JavaScript?
- How does the 'unknown' type differ from 'any' in TypeScript?
- Tell me about the Event Loop in JavaScript: what does it consist of and in what order are synchronous code, microtasks, and macrotasks executed?
- Tell me about closures in JavaScript. How often do you have to use them in practice?