reading-notes

All About JS Pt 3

Q1) What is an expression in JavaScript?

In JS, an expression is a unit of code that resolves to a value.

There are two types of expressions:

  1. Those that have side effects (such as assigning values)

    ex) x = 7

    This expression uses the = operator to assign the value seven to the variable x. The expression itself evaluates to 7.

  2. Those that purely evaluate.

    ex) 3 + 4

    This expression uses the + operator to add 3 and 4 together and produces a value, 7.

Q2) Why would we use a loop in our code?

A loop can be used to execute a set of code as many times as needed until a desired endpoint is reached.

Q3) When does a for loop stop executing?

A for loop repeats until a specified condition evaluates to false.

Q4) How many times will a while loop execute?

A while statement executes its statements as long as a specified condition evaluates to true.