Clearing Javascript basics regarding variables

share link

by vsasikalabe dot icon Updated: Mar 2, 2023

technology logo
technology logo

Guide Kit Guide Kit  

Variable initialization is storing a value in a variable. At the time of variable creation, we can do variable initialization; otherwise, later, when you need that variable. A local variable comes before a global variable with the same name within the body of a function. We can effectively hide the global variable if you declare a local variable or function parameter with the same name as a global variable. JavaScript is used for variable Scope.  

JavaScript variables have only two scopes. 

  • Global Variables − These can be defined anywhere in your JavaScript code. 
  • Local Variables − A local variable will be used only within a function where it is defined. Function parameters are always local to that same function. 

Use the undefined to unset a variable in JavaScript. Not assigned any value to a Variable is of type undefined. If the variable being evaluated does not have an assigned value, a method or statement also returns undefined. If a value is not returned to a function, it returns undefined. A variable is declared but not assigned any value known as undefined. 

Keep the following rules in mind while naming your variables in JavaScript: 

  • JavaScript-reserved keywords are not allowed as variable names.  
  • JavaScript variable names do not allow a number as a first letter. They always begin with a letter or an underscore character.  
  • JavaScript variable names are case-sensitive.  

Here is an example of how to use Javascript basic Variables: 

Preview of the output that you will get on running this code from your IDE.



Follow the steps carefully to get the output easily.

  1. Download and Install VS Code on your Desktop.
  2. Open the VS Code and install Javascript ES6 Code Snippet and Code Runner from Extensions.
  3. Open the new file and save as filename.js
  4. Copy the code using the "Copy" button above, and paste it in your javascript file.
  5. 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 found this code snippet by searching for ' Clearing Javascript basics regarding variables' in kandi. You can try any such use case!

Environment Tested

I tested this solution in the following versions. Be mindful of changes when working with other versions.

  1. The solution is created in VS Code 1.73.1 version.
  2. JavaScript (ES6) code snippets v1.8.0
  3. Code Runner v0.11.8

Using this solution, we are able to Clearing Javascript basics regarding variables with simple steps. This process also facilities an easy way to use, hassle-free method to create a hands-on working version of code which would help us to Clearing Javascript basics regarding variables.


  1. For any support on kandi solution kits, please use the chat
  2. For further learning resources, visit the Open Weaver Community learning page