JS REST (1)
JS REST (1)
JavaScript Arrays
JavaScript arrays are used to store multiple values in a single variable. Arrays allow you
to perform operations such as adding, removing, and modifying elements.
Declaring an Array
let fruits = ["Apple", "Banana", "Cherry"]; // Creates an array with three elements
Array elements are accessed using their index (starting from 0):
Modifying an Array
fruits[1] = "Mango"; // Replaces "Banana" with "Mango"
console.log(fruits); // Output: ["Apple", "Mango", "Cherry"]
Array Methods
JavaScript Objects
Objects in JavaScript store data as key-value pairs and allow methods to manipulate
this data.
Creating an Object
let person = {
firstName: "John", // Property: first name
lastName: "Doe", // Property: last name
age: 30, // Property: age
greet: function() {
return "Hello " + this.firstName; // Method to return a greeting
}
};
Accessing Properties
console.log(person.firstName); // Output: John (Accessing property using dot notation)
console.log(person["lastName"]); // Output: Doe (Accessing property using bracket
notation)
Object Methods
Object Constructor
JavaScript Maps
The Document Object Model (DOM) allows JavaScript to dynamically manipulate HTML
content.
Selecting Elements
JavaScript Events
JavaScript events allow interaction between the user and the webpage.
onClick Event
document.getElementById("btn").onclick = function() {
alert("Button Clicked"); // Displays an alert when the button is clicked
};
onMouseOver Event
document.getElementById("hoverDiv").onmouseover = function() {
console.log("Mouse Over Detected"); // Logs a message when mouse hovers over
the element
};
onChange Event
onKeyUp Event
document.getElementById("textField").onkeyup = function() {
console.log("Key Pressed"); // Logs a message when a key is pressed and released
};
Event Listener
Window Object
Location Object
History Object
QuerySelectorAll