JavaScript Mathematical Operators, WEBDEV Course by Nakul Goel Day-2

What are Mathematical operators in JavaScript? What is Modulo in Programming Language? How to print in multiple lines using the \n operator?

ยท

3 min read

JavaScript Mathematical Operators, WEBDEV Course by Nakul Goel Day-2

This is the Second lecture of the WEBDEV Course by Nakul Goel, today we will be learning what are Mathematical/ Arithmetic Operators in JavaScript.

The detailed video lecture is below:-

Before moving ahead

Important channels to Follow and subscribe to:-

Youtube :- youtube.com/channel/UCS_0LK2cA_y4Lfl6tUfdQgw

GitHub :- github.com/01NakulGoel

Lets Start

Actually, this is very basic to understand, like in maths we have addition, subtraction, multiplication, and division. we also have the same thing in the programming languages but there are some important things to keep in mind while using this so let's start by understanding what are operators, operands, and results.

image.png

Operands:-

The quantity on which an operation is to be done.

Operators:-

Any symbol that indicates an operation to be performed such as (+,-,/,* etc.)

Types of Operators in JavaScript

1) Addition(+)

2) Subtraction (-)

3) Division (/)

4) Multiplication (*)

5) % (Modulo) output is remainder

This operator in a programming language is known as the modulo operator which provides a remainder when two operands are divided. let's understand it:-

image.png

when you do operation 5%2 then this operator will provide the remainder part as the value.

Use cases:- 1) it helps us to identify whether a number is odd or even. for ex: for an odd number, number%2 will always be 1 and for an even number, it will always be 0.

6) **(exponentiation operator) 2**4=2 , it basically give us the power.

we can re-write to understand 2*4 as 2222 which is 2 multiplied by itself for four times.

image.png

now let's understand some important things:-

yesterday we learned about strings i.e. what are strings and how they are used.

string addition - concatenation

when we combine strings together using the + operator it is known as concatenation as a string.

console.log('Rosy'+'Sharma')=RosySharma
console.log(   'Rosy' + '  ' + 'Sharma'   )=Rosy Sharma

\n

to print something in multiple lines we can use \n

1) console.log('Rahul, '\n' ,'Sharma)

concatenation can remove unwanted spaces due to ','

1) console.log('rahul' + '\n' + 'sharma')

2) console.log('rahul','\nsharma')

3) console.log('rahul\nsharma')

Assignment:

Q1 declare a variable called myNumber1 and assign it to value 10 and then console 10%2, declare another variable myNumber2 and assign it to value 5 and console myNumber2%2. then add both numbers and console its modulo by 2?

Q2 declare a variable myName and assign your name to it. declare another variable webdev and assign a value I will be a full stack developer. print both variables in different lines using \n?

Q3 declare a new variable named name1 and assign your name to it. in the console print My name is name1. it should display your name, use concatenation.

if you guys are learning from this course do comment and subscribe to the youtube channel and be regular.

Did you find this article valuable?

Support Nakul Goel's blog by becoming a sponsor. Any amount is appreciated!

ย