Exercise: JS Operators
Objective#
Your objective is to practice using and reading operators and operation results between JavaScript values.
Steps#
Exercise Repo: JavaScript Operators
Exercise 1#
- Declare 2 variables,
aandb, and assign 20 toaand 4 tob - Declare a variable
addthat uses the+operator to store the result of adding the values stored inaandb - Declare a variable
minusthat uses the-operator to store the result of subtracting the values stored inaandb - Declare a variable
multiplythat uses the*operator to store the result of multiplying the values stored inaandb - Declare a variable
dividingthat uses the/operator to store the result of dividing the values stored inaandb
You can print the value of the variables to the browser console (ex: console.log(add)) to check the result.
Exercise 2#
- Use the following code to answer the questions below:
- What is the value of: num + str?
- What is the value of: num + str2?
- What is the value of: num + isPresent?
- What is the value of: firstName + num?
- What is the value of: isPresent + str?
- What is the value of: firstName + lastName?
Use the code above to test and print the results.
Exercise 3#
- Use the following code to answer the questions below:
- What is the value of: val == str3?
- What is the value of: val === str3?
- What is the value of: !isAwake?
- What is the value of: ("eleven" == str4 && val >= str3)?
- What is the value of: (!isAwake || isAwake)?
- What is the value of: 0 == false?
- What is the value of: 0 === false?
- What is the value of: 0 != false?
- What is the value of 0 !== false?
Use the code above to test and print the results.