Explore Differences Between the var and let Keywords

preview_player
Показать описание
What is the difference between var and let in JavaScript? var and let are both used for variable declaration in javascript but the difference between them is that var is function scoped and let is block scoped. Variable declared by let cannot be redeclared and must be declared before use whereas variables declared with var keyword are hoisted.

JavaScript Let - The let keyword was introduced in ES6. Variables defined with let cannot be Redeclared. Variables defined with let must be Declared before use. Variables defined with let have Block Scope.

What is var in JavaScript? The var statement declares a variable. Variables are containers for storing information. Creating a variable in JavaScript is called "declaring" a variable: var carName; After the declaration, the variable is empty (it has no value).

What is the let keyword in JavaScript? let allows you to declare variables that are limited to the scope of a block statement, or expression on which it is used, unlike the var keyword, which declares a variable globally, or locally to an entire function regardless of block scope.

Where is my browser JavaScript console? To open the developer console in Google Chrome, open the Chrome Menu in the upper-right-hand corner of the browser window and select More Tools (greater than sign) Developer Tools. You can also use Option + ⌘ + J (on macOS), or Shift + CTRL + J (on Windows/Linux).

How to open the browser console? Keyboard shortcuts to open the console
Windows/Linux: Press Control + Shift + J.
Mac: Press Command + Option + J.

All you need to do to pass this test is to replace var with let:
let catName = "Oliver";
let catSound = "Meow!";

Рекомендации по теме