Code highlights logo



Create a Variable: let

The let keyword is used to declare a block-scoped variable. Unlike the var keyword, let allows you to declare variables that are limited to the scope of a block (i.e., surrounded by curly braces {}). This provides more control and avoids potential issues caused by variable hoisting.

To create a variable using let, it's pretty similar to the var

1let message = "Hello, World!";

In the example above, we declared a variable named message using the let keyword and assigned it the value of "Hello, World!". Now, you can use this variable throughout the block (e.g., inside an if statement or a loop) or within the scope of its containing function (if there is one).

Using let instead of var can help prevent variable leakage and make your code more maintainable by reducing unwanted global variables.



Declare a let variable named isStudent with the value true.


Print the value of isStudent to the console.


Declare a let variable named salary and assign it the value 50000.00.


Print the value of salary to the console.

Sign up to start coding

Already have an account?

Sign In

Course content