Explanation
Here is an explanation of the program:
1. Purpose
This program demonstrates how to declare variables to store text and numbers, update a variable's value, and display formatted messages in the console.
2. Key Concepts
- Variable Declaration (
constvs.let):constis used for values that should not change;letis used for values that will be reassigned. - Data Types: Uses Strings (text in quotes like
"JavaScript fundamentals") and Numbers (integers like1and decimals like0.25). - String Concatenation: Combining text and variables into a single message using the
+operator. - Updating Variables: Using the addition assignment operator (
+=) to increment a number.
3. Code Walkthrough
- Lines 1–3: Declares
courseandprogressas constants (const) because they stay fixed, whilelessonis declared withletso it can change later. - Line 5: Prints a greeting directly to the console using
console.log(). - Lines 6–7: Uses the
+operator to join the strings and variables together to display the current lesson and progress. - Line 8 (
lesson += 1;): Increases the value oflessonfrom1to2. - Line 9: Prints the updated lesson number to the console.
4. Output
Hello, Codinx Labs!
JavaScript fundamentals - lesson 1
Progress: 0.25
Next lesson: 2