Information about cookies on this page

Our website uses cookies to ensure the functionality of the website, to collect and analyze information about the performance and usage of the website. Privacy Policy

  • Courses
    • Discord
    • Twitter
    • Linkedin
    • Facebook
    • Instagram
  • Pricing
  • English
  • Čeština
  • Deutsch
  • Русский
Sign inStart free
  • Courses
  • Pricing

Community

Sign in
  
  • Courses
    • Discord
    • Twitter
    • Linkedin
    • Facebook
    • Instagram
  • Pricing
  • English
  • Čeština
  • Deutsch
  • Русский
Sign inStart free
  • Courses
  • Pricing

Community

Sign in

Summary

In this lesson, you learned that:

  • A program is a list of statements that run one after another, from top to bottom. We end each statement with a semicolon ;.
  • console.log() prints to the console. Several values separated by commas are printed on one line, with spaces between them: console.log("Age:", 25) prints Age: 25.
  • Text (a string) is written in quotes, numbers without them.
  • The arithmetic operators are +, -, *, / and % (remainder). Multiplication and division are done before addition and subtraction; parentheses change the order.
  • Decimal numbers are written with a dot: 1.5. A number is even when its remainder after dividing by 2 (number % 2) is 0.
  • Comments are notes that the computer ignores: // up to the end of the line, /* */ over several lines. You can also use them to switch code off (comment it out).
  • Variables store values under a name: let score = 0;. You change the value with =, without let: score = score + 1;.
  • Names are written in camelCase (firstName), can't start with a digit or contain spaces, and uppercase and lowercase letters matter.
  • Constants (const) can't be changed: trying to do so ends with TypeError: Assignment to constant variable. Use const for values that don't change and let for the others.
  • + adds numbers and joins text. If one side is text, the result is text: "5" + 3 is "53". typeof tells you the type of a value: number or string.
  • Template literals in backticks insert values into text: `I am ${age} years old.`
  • An error message has a type and a description. SyntaxError means that the code is written wrongly, and nothing runs; ReferenceError means an unknown name; TypeError means something the value doesn't allow.

In the next lesson, Conditions, your programs will learn to make decisions: to do one thing or another, depending on the values of variables.

Instructions

  1. 1

    Before you go on, try it all out on a small task: a receipt from a coffee shop.

    Create a constant total with the price of two coffees and one cake. Calculate it from coffeePrice and cakePrice.

  2. 2

    Using a template literal, print the last line of the receipt: Total: 11.5 EUR

Back

15/15

  1. 1. Printing
  2. 2. Arithmetic Operations
  3. 3. Comments
  4. 4. Variables
  5. 5. Changing a Variable's Value
  6. 6. Quiz: The Order of Commands
  7. 7. Constants
  8. 8. Division and Remainder
  9. 9. Joining Text
  10. 10. Text and Numbers
  11. 11. Quiz: Text and Numbers
  12. 12. Template Literals
  13. 13. Quiz: Template Literals
  14. 14. Reading Errors
  15. 15. Summary
Next

Try it yourself

Do this exercise right here in your browser. No account needed.