Nested block is redundant
52 </div>
53 </div>
54 )
55 {}56}
Nested block is redundant
49 clearInterval(interval);
50 }
51 })
52 {/*<div className="w-full">*/}53 return (
54 <div className={`ml-auto mr-auto flex overflow-hidden mt-7 mb-7 ${styles.imageCarousel} min-h-xl`}>
55 {images}
Nested block is redundant
55 {images}
56 </div>
57 )
58 {}59}
Description
In JavaScript, prior to ES6, standalone code blocks delimited by curly braces do not create a new scope and have no use.
For example, these curly braces do nothing to foo
:
{
var foo = bar();
}
In ES6, code blocks may create a new scope if a block-level binding (let
and const
), a class declaration or a function declaration (in strict mode) are present. A block is not considered redundant in these cases.
Bad Practice
{}
if (foo) {
bar();
{
baz();
}
}
function bar() {
{
baz();
}
}
{
function foo() {}
}
{
aLabel: {
}
}
Recommended
while (foo) {
bar();
}
if (foo) {
if (bar) {
baz();
}
}
function bar() {
baz();
}
{
let x = 1;
}
{
const y = 1;
}
{
class Foo {}
}
aLabel: {}