Basics of Javascript
Basics of Javascript
Math in JavaScript
/ This is use for division. * This is use for multiplication.
In JavaScript math operation are done according to BODMAS/Order of Operation
and JavaScript follows the same rules multiply and divide are done first. Add and
subtract are done after .
One thing to note is that multiply and divide have the same priority so if we have
both in a calculation it will calculate from left to right
Add and subtract also have the same priority if we have both in the calculation it will
also calculate from left to right
We can use brackets to control which part of the calculation gets done first
weird behavior of math in JavaScript first we need to learn some terminology in
programming whole numbers like 2-3 and four are called integers decimal numbers
like 2.2 and 2.5 are called floating point numbers or floats and unfortunately
computers have a problem working with floats
CODE FOR ROUNDING A NUMBER IN JAVASCRIPT: Math.round(2.2)
Note: Make sure you use capital M since JavaScript is case sensitive
CODE FOR DISPLAYING POPUP: alert (‘helllo’)
CODE TO REMOVE ALL THE HTML AND JUST DISPLAY ONE WORD:
document.body.innerHTML=('manahil')
STRINGS
A String represent text.
Character:
1.Letter
2. Number
3.Symbol
4.Escape character a. \’ this is to represent text
b.\n newline character used to create newline
console.log is used to display value or string in console.
VARIABLES
Variable is a container in which we can save value (number or string) for later use
let is used to create variable.
All the variable name should use camel case. It is the standard for
JavaScript.
TERNARY OPERATOR