User-defined variables in JavaScript
Without variables, programming languages are next to useless. Fortunately, JavaScript's variable system is incredibly powerful and versatile. This article shows you how to use JavaScript variables to store numbers, text strings, objects, and other data types. Once you've stored this information, you can use it anywhere in your program.
All about JavaScript variables
Here's what you'll learn in this article:
- What is a user-defined variable in JavaScript?
- Data types in JavaScript variables
- How to create JavaScript variables
- How to store data types in JavaScript variables
- Tips for naming JavaScript variables
- Dynamic typing and JavaScript variables
- How to work with string variables
- What you need to know about variable scope
What is a user-defined variable in JavaScript?
All JavaScript programming happens in an environment like a web browser, Node, or Bun.js. Each of these environments has its own set of pre-defined variables like window
and console
. These variables are not user-defined because they are set by the environment. Another kind of variable is the user-defined variable defined by other developers, such as in third-party frameworks or libraries you use. Then there are variables you create while writing your programs, using the let
and const
keywords. These are defined by you, the user. This article is about how to create your own user-defined variables.