JavaScript
JavaScript (JS) is a lightweight, interpreted, or just-in-time compiled programming language with first-class functions. Most known scripting language for web pages.
What are Variables?
Variables are containers for storing data (storing data values). Variables are used for holding values and are used in expressions. Declare using var, let, or const
- var- used in older browsers
- let- newer, the keyword we will be using
- const- declares a variable that can’t be changed
JavaScript Identifiers
All JavaScript variables must be identified with unique names, called identifiers. Identifiers are case sensitive.
- Names can contain letters, digits, underscores, and dollar signs.
- Names must begin with a letter
- Names can also begin with $ and _ (but we will not use it in this tutorial)
- Names are case sensitive (y and Y are different variables)
- Reserved words (like JavaScript keywords) cannot be used as names.
JavaScript Data Types
JavaScript variables can hold numbers like 100 and text values like “John Doe”. Text values are called strings, using quotes. Number values are written without quotes.
Value = undefined
In computer programs, variables are often declared without a value. The value can be something that has to be calculated, or something that will be provided later, like user input.