You are on page 1of 2

JavaScript Course Lecture Notes

Topic: Values and Variables


Understanding Values

· A value is the most basic unit of information in programming.

· Examples of values include text (e.g., "Jonas"), numbers (e.g., 23), and mathematical results
(e.g., 61).

#Code

console.log("Jonas"); // Output: Jonas

console.log(23); // Output: 23

Declaring Variables

· Variables allow us to store and reuse values.

· 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

firstName = "Matilda"; // Changing the value of 'firstName' to "Matilda"

Naming Conventions for Variables

· Follow naming conventions:

1. Use camelCase for variable names (e.g., firstName, personAge).

2. Avoid starting variable names with numbers.

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.

· Descriptive variable names improve code readability.

You might also like