L
L
lssssssssssl2021-06-17 17:13:24
JavaScript
lssssssssssl, 2021-06-17 17:13:24

What is a "Block"?

I came across this line on the Internet "Any block of code in curly braces becomes a local environment."
How to explain in an accessible language that curly braces if or for, for example, create a block scope, but a literal object obj = {} or class name{} does not. How are their brackets so different from each other?
What is this "Block" of yours really?60cb5809f2285150441607.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Sokolov, 2021-06-17
@lsssssssssl

Instead of a block, there may well be a single instruction.

if (a > b) console.log("a win");

if (a > b) {
  console.log("b lost");
  console.log("a won");
}
The same with for (), and with just-code.
But the substitution focus will not work with classor an object literal.
Disclaimer. This is, of course, an attempt at an "accessible explanation". In fact, you need to familiarize yourself with the syntax of the language. Otherwise, a question about function, and then about parentheses will follow)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question