Menu

JavaScript Before React: Everything You Need to Know
πŸ“°

JavaScript Before React: Everything You Need to Know

DEV Community: frontendΒ·Hamed FaraziΒ·8 days ago
#Vtao6WaB
#devtofrontend#devto#dev#counter#enter
Reading 0:00
15s threshold

1. Variables: var , let , and const

Variables allow us to store data.

JavaScript provides three ways to declare variables:

var

let

const

var

var is the older way of declaring variables.

var framework = " React " ;

console . log ( framework ); // React

Enter fullscreen mode

Exit fullscreen mode

However, var has some important problems.

For example, it is function-scoped rather than block-scoped.

if ( true ) { var framework = " React " ; }

console . log ( framework ); // React

Enter fullscreen mode

Exit fullscreen mode

The variable escapes the if block.

This behavior can create unexpected bugs.

let

let allows you to declare variables that can be reassigned.

let age = 25 ;

age = 26 ;

console . log ( age ); // 26

Enter fullscreen mode

Exit fullscreen mode

Unlike var , let is block-scoped.

if ( true ) { let framework = " React " ; }

console .…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.