More About Operators and Expressions

CS133JS Beginning Programming: JavaScript

Topics by Week 
1. Intro to JavaScript programming6. Arrays
2. Functions, Variable scope, Operators and Expressions7. Functions
3. Conditional Statements8. Objects
4. Loops9. DOM
5. Midterm10. Final

 

Table of Contents


Review

Math Operators

JavaScript has all the math operators you know: +, -, /, * and one you might not: % (the modulo operator)

There are increment and decrement operators:

Comparison Operators

 


More on Operators and Expressions

Review: An expression is a unit of code that can be evaluated to some value.

Combined assignment and math operators

You can shorten the way you write statements that do a math operation and assign the result to a variable. For example a = a + 5 can be shorted to a += 5. Here are more examples:

 

The range of numbers that can be represented

Run this code in the console to see what the limits are for numeric expressions in JavaScript.

Representation of infinity

 


Reference

MDN Reference: Number


Creative Commons License Beginning JavaScript Lecture Notes by Brian Bird, written 2018, revised , are licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.