What are Variables?


In programming, a variable is used to store information that can be used and changed later in a program. Just like we store items in a box, we store data in variables.

Variables help programs remember values such as names, numbers, scores, and settings. Without variables, programs would not be able to handle changing data or perform useful tasks.

Learning how variables work is one of the most important steps in becoming a programmer.

Why Variables Are Important

  • They store information for later use  
  • They allow programs to work with changing data 
  • They make programs flexible and dynamic
  • They help organize data clearly  

Every real application uses variables to manage data.

This example creates a variable called userName and stores the value Ravi in it. The console.log() function then displays this value in the console.

This shows how variables store and provide information to the program.

Here, the variable score first stores the value 10. Later, the value is changed to 20.

This shows that variables can hold different values at different times while the program is running.

This example shows how variables are used to create dynamic messages. Instead of writing fixed text, programs can change output based on data.

Understanding variables is the foundation for learning conditions, loops, and functions in JavaScript.