In this example, you declared a variable named y and assigned it the value of 100. Within the if statement block, we declare another variable also named y and assign it the value of 20. This new y variable only exists within the if block, so when we log its value, it outputs 20. When we log the value of y again outside of the if block, it outputs 100, which is the value of the original y variable.
The const keyword declares a variable that is also block-scoped, but it cannot be reassigned once it has been declared unlike the Let variable. For example,
javascriptCopycodeconstz=15;z=20;// This will throw an error
In this example, you will declare a variable named z and assign it the value of 15. When you try to reassign it to 20, you will get an error because z is a const variable and cannot be reassigned.