Welcome to the JavaScript Basics Tutorial! This guide will help you understand the fundamentals of JavaScript, a programming language used to create interactive web pages.

Introduction

JavaScript is a versatile language that allows you to create dynamic and interactive web pages. It is an essential skill for web developers and is supported by all modern web browsers.

Basic Syntax

Here's a simple example of JavaScript syntax:

console.log("Hello, World!");

This code will display "Hello, World!" in the console.

Variables

Variables are used to store data values. In JavaScript, you can declare variables using the var, let, or const keywords.

var message = "Hello, World!";
console.log(message);

Data Types

JavaScript has several data types, including:

  • String: Text values, such as "Hello, World!"
  • Number: Numeric values, such as 5 or 3.14
  • Boolean: True or false values
  • Object: Complex data structures, such as arrays or objects

Functions

Functions are blocks of code that perform a specific task. Here's an example of a simple function:

function greet(name) {
  console.log("Hello, " + name + "!");
}

greet("Alice");

This function will greet the person named "Alice".

Events

JavaScript allows you to create interactive web pages by responding to user actions, such as clicks or key presses. Here's an example of a button click event:

document.getElementById("myButton").addEventListener("click", function() {
  console.log("Button clicked!");
});

DOM Manipulation

The Document Object Model (DOM) is a programming interface for HTML and XML documents. JavaScript can be used to manipulate the DOM, allowing you to dynamically change the content of a web page.

document.getElementById("myElement").innerHTML = "New content!";

This code will change the text inside the element with the ID "myElement".

Learning Resources

For more information on JavaScript, check out the following resources:

JavaScript Logo