Repository navigation
JS Fundametals
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.

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
-
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
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.
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.
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.
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 )
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.
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.
- 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.
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.
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.
RECAP
- .length is a property of strings that returns the number of characters in a string.
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.
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.
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.
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()
METHODE 1 - .toLowerCase()
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.
- Define variables
- Use operations (+, -, /, *)
- Complete existing functions
- Work with numbers
- Work with strings
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

Greater than or equal

Strictly less than

Less than or equal

Voorbeeld som:
Voorbeeld som:
