Operator | Description |
---|---|
+ | Addition |
- | Subtraction |
* | Multiplication |
** | Exponentiation |
/ | Division |
% | Modulus (Division Remainder) |
++ | Increment |
-- | Decrement |
Operator | Example | Same As |
---|---|---|
= | x = y | x = y |
+= | x += y | x = x + y |
-= | x -= y | x = x - y |
*= | x *= y | x = x * y |
/= | x /= y | x = x / y |
%= | x %= y | x = x % y |
**= | x **= y | x = x ** y |
Operator | Description |
---|---|
== | equal to |
=== | equal value and equal type |
!= | not equal |
!== | not equal value or not equal type |
> | greater than |
< | less than |
>= | greater than or equal to |
<= | less than or equal to |
? | conditional (ternary) operator |
Operator | Description |
---|---|
&& | logical and |
|| | logical or |
! | logical not |
function multiply(a, b)
{
return a * b;
}
console.log(multiply(5,5));
let company = "Revolution";
let service = 'Web Development';
//length property
let txt = "Revolution IT Solutions";
let length = txt.length;
//string slice()
let str = "Kolhapur, Mumbai, Pune";
let part = str.slice(10, 15);
//string substring()
let str = "Kolhapur, Mumbai, Pune";
let part = str.substring(10, 15);
//String substr()
let str = "Kolhapur, Mumbai, Pune";
let part = str.substr(10, 5);
//Replacing String Content
let text = "Please visit company!";
let newText = text.replace("company", "Revolution IT Solutions");
//Lowecase and Uppercase
let text1 = "revolution";
let text2 = text1.toUpperCase();
let text1 = "REVOLUTION";
let text2 = text1.toLowerCase();
//JavaScript String trim()
let text1 = " Revolution ";
let text2 = text1.trim();
An array can hold many values under a single variable, and you can access the values by referring to an index number
//There are two ways to declare Array
let cities = new Array();
let cities = [];
cities =['Kolhapur', 'Pune', 'Mumbai']
//How to access array elements
console.log(cities[0])
console.log(cities[1])
The real strength of JavaScript arrays are the built-in array properties and methods
//Length property
const cities = ["Kolhapur", "Pune", "Mumbai", "Nashik"];
let length = cities.length;
//Adding element to array
const cities = ["Kolhapur", "Pune", "Mumbai", "Nashik"];
cities.push("Nagpur");
//Remove last element of an array
const cities = ["Kolhapur", "Pune", "Mumbai", "Nashik"];
cities.pop();
//concatenating array
const cities1 = ["Kolhapur", "Satara"];
const cities2 = ["Pune", "Mumbai""];
const cities = cities1.concat(cities2);
//Removing elements using splice() method
const cities = ["Kolhapur", "Pune", "Mumbai", "Nashik"];
cities.splice(0, 1);
//sorting an array
const fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.sort();
//There are two ways to declare Object
let car = new Object();
let car = {};
car = {
name: "A7",
brand: "Audi",
capacity: 5
};
//How to access properties of an Object
console.log(car['name'])
console.log(car['brand'])
//onclick attribute
<button onclick="showDate()">Show Date</button>
//Adding onclick event listener to button
<button id="showDate">Show Date</button>
<p id="dateinfo"></p>
document.getElementById("showDate").addEventListener("click", displayDate);
function displayDate()
{
document.getElementById("dateinfo").innerHTML = Date();
}
List of common HTML events
Event | Description |
---|---|
onchange | An HTML element has been changed |
onclick | The user clicks an HTML element |
onmouseover | The user moves the mouse over an HTML element |
onmouseout | The user moves the mouse away from an HTML element |
onkeydown | The user pushes a keyboard key |
onload | The browser has finished loading the page |
input | The event occurs when an element gets user input |