JavaScript_Full_Detailed_Notes_Complete_Extended (1)
JavaScript_Full_Detailed_Notes_Complete_Extended (1)
Introduction to JavaScript:
- JavaScript allows you to update content, control multimedia, animate images, etc.
1. Variables in JavaScript
Example:
var x = 5;
let y = 10;
const z = 15;
2. Data Types
- JavaScript variables can hold many data types such as numbers, strings, objects, and more.
Example:
function add(a, b) {
return a + b;
4. Conditional Statements
Example:
if (x > 10) {
} else {
5. Loops
- Loops are used to repeatedly run a block of code until a condition is met.
Example:
while (i < 5) {
console.log(i);
i++;
6. DOM Manipulation
- JavaScript can interact with the Document Object Model (DOM) to manipulate web pages.
- You can access and modify HTML elements using methods like getElementById(), querySelector(),
etc.
Example:
document.querySelector(".myClass").style.backgroundColor = "yellow";
7. JavaScript Events
- JavaScript can respond to user actions via events, such as clicking a button or hovering over an
element.
Example:
document.getElementById("myButton").addEventListener("click", function() {
alert("Button clicked!");
});
8. JavaScript Objects
Example:
var car = {
make: "Toyota",
model: "Corolla",
year: 2020,
start: function() {
console.log("Car started");
};
9. JavaScript Arrays
Example:
- You can manipulate arrays using methods like push(), pop(), and shift().