Fundamentals (Paid)
  • 🚀Course Overview
  • Course Logistics
    • 🏫Course Methodology
      • 🧩Course Components
      • 💬Community Channels
      • 🎲Course Projects
    • 💻Required Hardware and Software
      • ☝️Required Software 1
      • ✌️Required Software 2
      • 👍Recommended Setup
    • 🗓️Schedule
    • 💡Tips and Tricks
      • 📒Coding Strategies
      • 🛠️Tooling Pro Tips
    • 🎓Post-Course
      • 🎓LinkedIn Certificates
      • 🚂Bootcamp Admission Criteria
  • 1: Introduction
    • 1.1: What is Coding?
    • 1.2: Web Browsers
    • 1.3: Command Line
    • Additional Resources 1
  • 2: Basic Data Manipulation
    • 2: Operators and Expressions
      • 2.1: Arithmetic Operators | Mathematical Expressions
      • 2.2: Assignment Operators | Variables
    • 2.3: Our First Program
    • Additional Resources 2
  • 3: Structuring and Debugging Code
    • 3.1: Functions
    • 3.2: Errors
    • Additional Resources 3
  • 4: Conditional Logic
    • 4.1: Intro to Logic
    • 4.2: Pseudo-Code, Boolean Or
    • 4.3: Boolean AND, NOT
    • 4.4: Input Validation
    • Additional Resources 4
  • 5: Managing State and Input Validation
    • 5.1: Program Lifecycle and State
    • 5.2: Program State for Game Modes
    • Additional Resources 5
  • 6: Arrays and Iteration
    • 6.1: Arrays
    • 6.2: Loops
    • 6.3: Loops with Arrays
    • Additional Resources 6
  • 7: Version Control
    • 7.1: Git
    • Additional Resources 7
  • 8: GitHub
    • 8.1: Intro to GitHub
    • 8.2: GitHub Fork and Clone
    • 8.3: GitHub Pull Request
    • 8.4: GitHub Repo Browsing
    • 8.5: Deployment
    • Additional Resources 8
  • 9: JavaScript Objects
    • 9.1: JavaScript Objects
    • 9.2: Card Deck Generation with Loops
  • 10: Advanced
    • 10.1 HTML
    • 10.2: CSS
    • 10.3: The Document Object Model
    • 10.4: DOM Manipulation
    • 10.5: Advanced Debugging with Sources Tab
  • 11: POST COURSE EXERCISES
    • DOM
    • Further Readings
  • In-Class Exercises
    • Day 2: Basic File and Data Manipulation
    • Day 3: Functions
    • Day 4: If Statements, Boolean Or, Boolean And
    • Day 5: Program State
    • Day 6: Scissors Paper Stone Redux
    • Day 7: Loops
    • Day 8: Arrays and Loops
    • Day 9: Beat That Redux
    • Day 10: Moar Cards / Chat Bot
    • Day 11: Blackjack Redux, DOM
  • Projects
    • Project 1: Scissors Paper Stone
      • Project 1: Scissors Paper Stone (Part 1)
      • Project 1: Scissors Paper Stone (Part 2)
    • Project 2: Beat That!
    • Project 3: Blackjack
  • Past Projects
    • Drawing With Emojis
    • Guess the Word
Powered by GitBook
On this page
  • Learning Objectives
  • Introduction
  • String Concatenation (addition operator)
  1. 2: Basic Data Manipulation
  2. 2: Operators and Expressions

2.1: Arithmetic Operators | Mathematical Expressions

Learning Objectives

  • Be familiarized with the list of arithmetic operators available

  • Try writing your own mathematical expressions!

  • Use the addition operator on strings

Introduction

Arithmetic operators takes numerical values as their operands (the values on both sides of the operator) and returns a single numerical value.

6 + 13 // '+' is the operator; both values, '6' and '13', are the operands

In the case above, 13, being on the right side, is added to 6, on the left.

The standard arithmetic operators are addition (+), subtraction (-), multiplication (*), and division (/). These operators work as they do in most other programming languages when used with floating point numbers (decimals).

Here is a list of arithmetic operators:

Operator
Description
Example

Addition ( + )

a + b Result: adds b into a.

3 + 9 Result: 12

Subtraction ( - )

a - b Result: subtracts b from a

6 - 8 Result: -2

Multiplication ( * )

a * b Result: a is multiplied by b

4 * 2 Result: 8

Division ( / )

a / b Result: a is divided by b

9 / 3 Result: 3

Remainder or Modulo ( % )

a % b Result: remainder of a divided by b

10 % 6 Result: 4

Increment ( ++ )

a++ Result: adds 1 to a

Decrement ( -- )

a-- Result: subtracts 1 from a

Exponential ( ** )

a ** b Result: a is multiplied by itself by b number of times.

String Concatenation (addition operator)

You are able to use the arithmetic addition operator to combine two strings together, this can also be known as concatenation of two strings. The same addition operator + that is used on numbers are applied to strings in this case.

Using the logical addition operator we can assign a combined string to a variable.

// String Concatenation using logical operators

const string = 'Good morning' + ' ' + 'class';

console.log(string)
// 'Good morning class'

In the example above we are taking the operands strings/ values Good morning , ' ' and class to create a single string reading Good morning class . They are being combined through the + sign which is the operator.

Previous2: Operators and ExpressionsNext2.2: Assignment Operators | Variables

Last updated 2 years ago

Though it should be noted that if you add two different data types together this can cause type coercion. Which is a fancy way of saying, JavaScript will alter the datatypes to accommodate the logic used. If you want to know more about type coercion please read about it

here.