Professional Documents
Culture Documents
005 Values and Variables (Notes)
005 Values and Variables (Notes)
· Examples of values include text (e.g., "Jonas"), numbers (e.g., 23), and mathematical results
(e.g., 61).
#Code
console.log(23); // Output: 23
Declaring Variables
· To declare a variable, use the let keyword followed by the variable name and an initial value.
#Code
let firstName = "Jonas"; // Declaring a variable named 'firstName' with the value "Jonas"
Variable Reusability
· Variables enable us to change the stored value in one place, and it automatically updates
everywhere it's used.
#Code
3. Use only letters, numbers, underscores, or the dollar sign in variable names.
4. Avoid using reserved JavaScript keywords (e.g., new, function) as variable names.
5. Consider using uppercase letters for constants (e.g., PI) to indicate values that won't change.