0% found this document useful (0 votes)
5 views14 pages

Js Numbers

The document provides an overview of numbers in JavaScript, detailing the types (integers and floats) and how to convert strings to numbers. It explains arithmetic operators, their precedence (PEMDAS), and shorthand operators for assignment. Additionally, it introduces increment and decrement operations and presents a challenge to calculate the average of five subject grades.

Uploaded by

nathanllagas28
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views14 pages

Js Numbers

The document provides an overview of numbers in JavaScript, detailing the types (integers and floats) and how to convert strings to numbers. It explains arithmetic operators, their precedence (PEMDAS), and shorthand operators for assignment. Additionally, it introduces increment and decrement operations and presents a challenge to calculate the average of five subject grades.

Uploaded by

nathanllagas28
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Numbers

Convert Strings to Numbers


Arithmetic Operators
PEMDAS
Shorthand Operators JavaScript
Increment / Decrement
Challenge
Numbers
One of the datatypes in JavaScript. It maybe a
whole number or a decimal.

There are two types of numbers in JavaScript

Integer - Whole Numbers


Float - Decimal Numbers
Quick Exercise
Value Type

5 Number (Integer)

'3.1376' String

3.14 Number (float)

6.54238 Number (float)

"12" String
Convert Strings to Numbers

Unsuccessful conversions will result into a NaN (Not A


Number) Value
Assignment Operator

Is used to put/assign values to variables.

Operator Function Example

= Assignment let num = 12


Arithmetic Operators
Operators that can perform mathematical equations on numbers

Operator Function Example

+ Addition 5+5

- Subtraction 5-5

* Multiplication 5*5

/ Division 5/5

** Exponent 5 ** 2

% Modulus (Remainder) 5%2


Operators that can perform mathematical equations on numbers
Arithmetic Precedence
PEMDAS is followed in the order of precedence.

1. Parentheses
2. Exponent
3. Multiplication
4. Division
5. Addition
6. Subtraction
Arithmetic Precedence

Given the code what do you think will be the output?


Arithmetic Precedence

Given the code what do you think will be the output?


Shorthand Operators
Performs an arithmetic operator to a variable and assigns it to itself.

Operator Usage Same As

+= x += 5 x=x+5

-= x -= 5 x=x-5

*= x *= 5 x=x*5

/= x /= 5 x=x/5

**= x **= 2 x = x ** 2

%= x %= 5 x=x%5
Increment / Decrement
Adds / Subtracts 1 to a variable

Operator Usage Description

++ ++x or x++ Adds 1

-- --x or x-- Subtracts 1


Prefix
Postfix
Lesson Challenge

Try to do this challenge using


the things you've learned.
Create a program that uses
variables for 5 subject grades.
Get the average of all the
grades and display it.

You might also like