JavaScript Basics
Introduction to JavaScript
JavaScript is a programming language used to add interactivity to web pages. It's executed on the client-side by web browsers.
// Example JavaScript code console.log('Hello, World!');
Try it yourself:
Variables and Data Types
JavaScript supports various data types, including numbers, strings, and booleans. Variables are declared using let, const, or var.
let name = 'John'; const age = 30; var isAdmin = true;
Interactive Example:
Control Structures
Control structures like if/else statements and loops are used to control the flow of your JavaScript code.
if (age > 18) { console.log('You are an adult.'); } else { console.log('You are a minor.'); }
Interactive If/Else Example:
Functions
Functions are reusable blocks of code that perform a specific task. They can take arguments and return values.
function greet(name) { console.log(`Hello, ${name}!`); } greet('Alice');
Interactive Greeting Example:
Basic DOM Manipulation
JavaScript can interact with the Document Object Model (DOM) to dynamically change web page content.
document.getElementById('myElement').innerHTML = 'New content!';
Try it yourself:
Original content.