Skip to content

JS Fundametals

lynnvdbo edited this page Jan 28, 2026 · 37 revisions

Variables - Anatomy of variable declarations

Scherm­afbeelding 2025-12-06 om 17 27 31

RECAP

  • let is a keyword that we use to create a new variable.
  • It is then followed by the name of the variable.
  • Then followed by the equal sign = which assigns it (or gives it a value)
  • Then followed by the value of the variable.
  • Make sure to give descriptive names for your variables.

Variable operations

Scherm­afbeelding 2
025-12-06 om 17 31 27

Scherm­afbeelding 2025-12-06 om 17 32 38

RECAP

  • The first time you define a variable, you have to define it with let.
  • The next time you use that variable, you should NOT use let anymore. Directly use the variable by its name.
  • variable + 3 performs an operation that adds 3 to the variable. It does NOT modify the variable.
  • Be careful of hardcoding. Do not replace variable + 3 with a number because we want our code to work for any value given to variable

Addition & multiplication

Scherm­afbeelding 2025-12-06 om 17 46 06 Scherm­afbeelding 2025-12-06 om 17 46 16 Scherm­afbeelding 2025-12-06 om 17 50 36

CHAPTER RECAP

  • The first time you define a variable, you have to define it with let
    
  • The next time you use that variable, you should NOT use let any more. Just directly use the variable by its name.
    
  • variable + 3 performs an operation that adds 3 to the variable. It does NOT modify the variable.
    
  • Be careful of hardcoding. Do not replace variable + 3 with a number because we want our code to work for any value given to variable.
    
  • The + operator adds the 2 numbers on its left and right
    
  • The * operator multiplies the 2 numbers on its left and right
    

Introduction to functions

These are also examples of functions.

A function is a reusable piece of code that performs some logic and gives you a result.

For example, a sum function is a function that sums 2 numbers and returns the result. For example, assuming we have a function sum, then writing sum(3, 5) will give us the sum of 3 and 5 which is 8.

The function sum will then contain the needed logic to compute the sum of these 2 numbers.

Scherm­afbeelding 2025-12-06 om 18 02 51 Scherm­afbeelding 2025-12-06 om 18 03 01

The function keyword

The function keyword is used to define a function. This allows you to group related code logic together to make a reusable task. More on that later on. The return keyword

As you can see, the last line of that function is return. This is an important keyword. return is used to give the result of the function.

Let's take an example in English:

What is the result of doubling 4?
The result is 8

By having return number * 2 you're saying that the result of the double function is: number * 2 which in this example would be 8.

We will dive deeper into how return works in the next few chapters, for now, remember that most functions will need to give the result of the computation by having a return at the end.

Note that the return keyword can only be used inside a function.

Scherm­afbeelding 2025-12-06 om 18 09 09

RECAP

  • function is a reusable piece of code that performs some logic and gives you a result
  • The return keyword allows the function to give the result of its computation.
  • return keyword can only be used inside a function.
Scherm­afbeelding 2025-12-06 om 18 40 00 Scherm­afbeelding 2025-12-06 om 18 40 21

CHAPTER RECAP

  • A function is a reusable piece of code that performs some logic and gives you a result
  • The return keyword allows the function to give the result of its computation.
  • return keyword can only be used inside a function.
  • A parameter is a variable that a function receives.
  • Most functions will use that variable they receive and will compute the result based on it.
  • To call a function, you have to start with its name, then opening parentheses (, then the value you want to give to the parameter, and then a closing parenthesis )

Multiple parameters

Scherm­afbeelding 2025-12-06 om 18 54 21 Scherm­afbeelding 2025-12-06 om 18 54 32

RECAP

  • Functions can have multiple parameters, they should be separated by a comma (and a space for readability)
  • The argument is a value passed to a function. The argument becomes the parameter for that specific function call.

Variable scope

Scherm­afbeelding 2025-12-06 om 19 19 56 Scherm­afbeelding 2025-12-06 om 19 25 02 Scherm­afbeelding 2025-12-06 om 19 31 58

RECAP

  • The parameters of a function are only accessible inside that function. (This concept is called variable scope)
  • You can store/save the result of a function in a variable.

Chapter recap

  • Functions can have multiple parameters, they should be separated by a comma (and a space for readability)
  • The argument is a value passed to a function. The argument becomes the parameter for that specific function call.
  • The parameters of a function are only accessible inside that function. (This concept is called variable scope)
  • You can store/save the result of a function in a variable.

Intro to strings

In the first few chapters, you learned about numbers. In this one, you will learn about strings.

Programming languages have what we call data types, these are the different types that variables can hold. In real life, a number (for example 35) is different than a name (for example "Sam"). One of them is a number, the other one is a string.

Scherm­afbeelding 2025-12-06 om 23 07 59 Scherm­afbeelding 2025-12-06 om 23 09 03

RECAP

  • A string is a text, a set of characters that you may write to represent a name, city, country, description, product title, etc.
  • Strings have to start with a double quote " and end with one.
  • Forgetting the double quotes around strings is the most common mistake that beginners make.

String length

Scherm­afbeelding 2025-12-06 om 23 16 49 Scherm­afbeelding 2025-12-06 om 23 17 36 Scherm­afbeelding 2025-12-06 om 23 26 40

RECAP

  • .length is a property of strings that returns the number of characters in a string.
Scherm­afbeelding 2025-12-06 om 23 28 50

RECAP

  • A string is a text, a set of characters that you may write to represent a name, city, country, description, product title, etc.
  • Strings have to start with a double quote " and end with one.
  • Forgetting the double quotes around strings is the most common mistake that beginners make.
  • .length is a property of strings that returns the number of characters in a string.

Console.log

Scherm­afbeelding 2025-12-06 om 23 34 30

Recap

  • console.log() allows you to visualize your code in the console.
  • The console is only visible to you (the developer), but not the end-user.
  • console.log() helps you find bugs.

Console.log & functions

Scherm­afbeelding 2025-12-06 om 23 42 18

Recap

  • console.log does NOT replace return
  • console.log will never modify the result of a function; it will just show you a string or a number in the Console.

Sample usage

Scherm­afbeelding 2025-12-06 om 23 52 06

Chapter recap

  • console.log() allows you to visualize your code in the console.
  • The console is only visible to you (the developer), but not the end-user.
  • console.log() helps you find bugs.
  • console.log does NOT replace return
  • console.log will never modify the result of a function; it will just show you a string or a number in the Console.
  • Sample usage is meant to show you examples of how your functions will be called.
  • We will often console.log the sample usage so that you can see its values in the console.
  • Beware of hardcoding - the sample usage is only meant as an example.

String methods

In this chapter, we'll learn about 2 methods that you can call on strings.

These are not properties but are rather methods. The reason why there's a distinction is that methods will perform an operation on the string. Let's see what that means by checking out the first method:

METHODE 1 - .toUpperCase()

Scherm­afbeelding 2025-12-06 om 23 56 53

METHODE 1 - .toLowerCase()

Scherm­afbeelding 2025-12-06 om 23 57 19 Scherm­afbeelding 2025-12-07 om 00 09 29 12-07 om 00.08.33.png…]()

RECAP

  • The .toUpperCase() method makes a new copy of a string while converting every single character to uppercase.
  • The .toLowerCase() method creates a copy of the string that is all in lower case.
  • Pay attention to the way those methods are called: .toUpperCase() with a capital U and capital C. Same for .toLowerCase() with a capital L and capital C.
  • he () at the end of the method are required.
Scherm­afbeelding 2025-12-07 om 00 22 40

Project recap

  • Define variables
  • Use operations (+, -, /, *)
  • Complete existing functions
  • Work with numbers
  • Work with strings

Booleans

Scherm­afbeelding 2026-01-27 om 20 41 38

Comparison Operators

In this chapter, we'll learn how to ask our program some basic questions, such as:

  • Is the age of the user 18?
    
  • Is the age strictly greater than 18?
    
  • Is the age greater than or equal to 18?
    
  • Is the age less than 18?
    

Strictly greater than Scherm­afbeelding 2026-01-27 om 20 47 58

Greater than or equal Scherm­afbeelding 2026-01-27 om 20 49 01

Strictly less than Scherm­afbeelding 2026-01-27 om 20 49 31

Less than or equal Scherm­afbeelding 2026-01-27 om 20 50 05

Chapter Recap

Scherm­afbeelding 2026-01-27 om 20 51 54

Voorbeeld som:

Scherm­afbeelding 2026-01-27 om 21 03 32 Scherm­afbeelding 2026-01-27 om 21 09 57 Scherm­afbeelding 2026-01-27 om 21 10 22

Equality comparison

Scherm­afbeelding 2026-01-27 om 21 16 54 Scherm­afbeelding 2026-01-27 om 21 17 41

Chapter Recap

Scherm­afbeelding 2026-01-28 om 20 50 26

Intro 'If Conditions'

Scherm­afbeelding 2026-01-28 om 20 51 38 Scherm­afbeelding 2026-01-28 om 20 52 25 Scherm­afbeelding 2026-01-28 om 20 52 35

Voorbeeld som: Scherm­afbeelding 2026-01-28 om 20 53 13

Branching

https://learnprogramming.online/app.html?id=678

Clone this wiki locally