JavaScript Tasks and Concepts
JavaScript Tasks and Concepts
JavaScript objects are collections of key-value pairs. These are used to store multiple values in a
single variable. Objects can hold properties (key-value pairs) and methods (functions).
Key Features:
- Properties can store any data type, including other objects and arrays.
Syntax:
let objectName = {
property1: value1,
property2: value2,
method1: function() {
};
Example:
let teluguKing = {
reign: "1509-1529",
introduce: function() {
}
};
// Accessing properties
// Calling methods
2. Confirm Box: Displays a message with OK and Cancel buttons, returning true or false.
Alert Box:
Confirm Box:
if (decision) {
} else {
Prompt Box:
Events are actions or occurrences that happen in the browser, such as clicking a button, loading a
Types of Events:
Example:
document.getElementById("greetButton").onclick = function() {
};
Event listeners are used to attach a function to a specific event. They provide a cleaner way to
Syntax:
element.addEventListener(event, function, useCapture);
Example:
document.getElementById("infoButton").addEventListener("click", function() {
});
1. Create a web page about Telugu kings using objects, events, and event listeners.
2. Build a form for a museum using prompt boxes and CSS styling.
3. Design a timeline for kings with interactive mouse events and toggling.
4. Create a history quiz with confirm boxes and dynamic event handling.
Clues: