- It must start with an underscore (), a letter (a to z or A to Z), or dollar ($) sign.
- After the first letter, we can use digits (0 to 9), for example, value 3.
A variable is declared outside the function or with a window so that we can access it from any function.
- var- The var statement declares a value globally scoped variable.
- let - It declares variables limited to the scope of a block statement where it is used.
- const -A constant holds a value that does not change.
Difference between undefined and undeclared variables.
An undefined variable has been declared but not initialized with a value. For example:
console.log(message); // undefined
Undeclared variables are always global. It has not been declared using var, let, or const keywords.
Preview of the output that you will get on running this code from your IDE.
Follow the steps carefully to get the output easily.
- Download and Install VS Code on your Desktop.
- Open the new file and save as example.js
- Run the code using (ctr+alt+N) Run button.
I hope you found this useful. I have added version information in the following sections.
I tested this solution in the following versions. Be mindful of changes when working with other versions.
- The solution is created in VS Code 1.73.1 version.
- Code Runner v0.11.8
- For any support on kandi solution kits, please use the chat
- For further learning resources, visit the Open Weaver Community learning page