JavaScript Basics
JavaScript Basics
It is one of the core technologies of the web, alongside HTML and CSS.
interactivity.
JavaScript is executed on the client side by web browsers, making it fast and
worldwide.
JavaScript offers several features that make it powerful and user-friendly:
development community.
In JavaScript, variables are used to store data. You can declare variables using
Data Types:
1. Primitive Types:
2. Non-Primitive Types:
programming.
JavaScript provides a variety of operators for performing computations and
logical operations.
3. Comparison Operators: ==, ===, !=, !==, >, <, >=, <=
Using these operators, you can manipulate data and create complex logical
expressions.
Control structures in JavaScript allow you to determine the flow of execution.
1. Conditional Statements:
2. Loops:
3. Exception Handling:
1. Function Declaration:
function greet() {
console.log("Hello, World!");
2. Function Expression:
console.log("Hello, World!");
};
3. Arrow Functions:
Functions can accept parameters and return values, making them highly
flexible.
Objects and arrays are fundamental in JavaScript for organizing data.
1. Objects:
- Example:
const person = {
name: "Alice",
age: 25,
greet: function() {
console.log("Hello!");
};
2. Arrays:
- Example:
1. Selecting Elements:
- document.getElementById("id")
- document.querySelector(".class")
2. Modifying Elements:
- element.style.color = "blue";
element.addEventListener("click", function() {
alert("Element clicked!");
});
Using the DOM, you can create dynamic, interactive web pages.
ES6 (ECMAScript 2015) introduced modern features to JavaScript, including: