RSSAmplifier

Ajay Karwal · Nov 7, 2020

Scoping Variables With A Block Statement

0
Sign in to vote or save

This site does not allow itself to be embedded. You can still read it on the original site — the toolbar below keeps your place in the directory.

A block is simply any code wrapped in curly braces { } . In JavaScript, you can use block scope and the let keyword to your advantage by defining variables that are only available to a block rather than polluting the global scope. Let’s look at two examples: const dateStr = '2020-05-04' ; var [ year , month , day ] = dateStr . split ( '-' ) ; // 'year' accidently gets redefined on the global scope…

Read on ajaykarwal.com

Comments

Nothing yet. Say the first thing.

    Sign in to join the conversation.

    Reading · Ajay Karwal · RSS Amplifier