In this tutorial, we will check variables in JavaScript. If you learnt any programming language before then you would have an idea what these variables are. For those who never heard this word before variables are simply named of storage locations. Meanwhile working on any program we store some values in different memory locations and variables simply reference to these memory locations and allow us to fetch values from these memory locations.
Page Contents
There are some rules as other languages while writing the identifiers of these variables.
- Name must start with a letter (a to z or A to Z), underscore( _ ), or dollar( $ ) sign.
- After first letter we can use digits (0 to 9), for example value1.
- JavaScript variables are case sensitive, for example name and Name are different variables.
Some valid variable names:
<script>
var x = 10;
var min_age="18;
var name="Owlbuddy";
</script>
Difference Between Local and Global Variables:
Local Variables:
Variables which we declare inside a block or inside a function are known as a local variable and where these variable are declared only that function or block can use these variables.
<script>
function show(){
var name="owlbuddy";//local variable
}
</script>
Global Variables:
Variables which we declare outside of the block or any function are known as global variables and these can use from anywhere in code.
<script>
var name="owlbuddy";//gloabal variable
function show1(){
document.writeln(name);
}
function show2(){
document.writeln(name);
}
</script>
Parvesh Sandila is a results-driven tech professional with 8+ years of experience in web and mobile development, leadership, and emerging technologies.
After completing his Master’s in Computer Applications (MCA), he began his journey as a programming mentor, guiding 100+ students and helping them build strong foundations in coding. In 2019, he founded Owlbuddy.com, a platform dedicated to providing free, high-quality programming tutorials for aspiring developers.
He then transitioned into a full-time programmer, where his hands-on expertise and problem-solving skills led him to grow into a Team Lead and Technical Project Manager, successfully delivering scalable web and mobile solutions. Today, he works with advanced technologies such as AI systems, RAG architectures, and modern digital solutions, while also collaborating through a strategic partnership with Technobae (UK) to build next-generation products.
