reading-notes

Class 8 Notes

Operators and Loops

Link to article: Expressions and Operators

Link to article: Loops


What is an expression in JavaScript?

An expression in JavaScript is a combination of values, variables, and operators that evaluates to a single value. There are two types of expressions: those that have side effects (such as assigning values) and those that purely evaluate.

Why would we use a loop in our code?

A loop allows us to repeat a set of instructions multiple times, which can be very useful when we need to perform the same task repeatedly. Loops can also help us to iterate over a list of items, such as an array or collection, and perform a set of instructions on each one. This can save us time and make our code more efficient.

When does a for loop stop executing?

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

How many times will a while loop execute?

A while loop will continue to execute until the condition that it is checking is no longer met. Therefore, the number of times a while loop will execute will depend on the condition it is checking.