JavaScript Closures - advanced Flashcards

1
Q

What is a code block and what does it allow us to do?

A

A code block is code surrounded with curly braces. We can use a code block to isolate a piece of code that does its own task, with variables that only belong to it:

{
    let name='Tom'
    console.log(name) // output - 'Tom'
}

console.log(name) // Error: message is not defined

Commonly code blocks are used for if statements and function bodies.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly