0% found this document useful (0 votes)
7 views2 pages

Java Script Basic

The document provides an overview of basic programming concepts including variables, data types, functions, conditionals, loops, and events in JavaScript. It explains how to declare variables using 'let', 'const', and 'var', and outlines common data types such as strings, numbers, booleans, arrays, and objects. Additionally, it demonstrates the use of functions, conditional statements, loops, and handling user events in the DOM.

Uploaded by

maxvelwilliam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views2 pages

Java Script Basic

The document provides an overview of basic programming concepts including variables, data types, functions, conditionals, loops, and events in JavaScript. It explains how to declare variables using 'let', 'const', and 'var', and outlines common data types such as strings, numbers, booleans, arrays, and objects. Additionally, it demonstrates the use of functions, conditional statements, loops, and handling user events in the DOM.

Uploaded by

maxvelwilliam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

.

Variables

Used to store data.

let name = "Alice"; // Can be changed later


const age = 25; // Constant, cannot be changed
var city = "New York"; // Older way (not recommended)

🟨 2. Data Types

Common types:

let name = "John"; // String


let age = 30; // Number
let isHappy = true; // Boolean
let colors = ["red", "green"]; // Array
let person = { name: "John", age: 30 }; // Object

🟨 3. Functions

Blocks of code that can be reused.

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

greet("Alice"); // Output: Hello, Alice

Or using arrow functions:

const greet = (name) => {


console.log("Hi " + name);
};

🟨 4. Conditionals

Run different code based on conditions.

let age = 18;

if (age >= 18) {


console.log("You are an adult");
} else {
console.log("You are a minor");
}

🟨 5. Loops

Repeat code.

for (let i = 0; i < 5; i++) {


console.log(i); // 0, 1, 2, 3, 4
}

🟨 6. Events & DOM

Reacting to user actions (like clicking a button).


HTML:

<button onclick="sayHello()">Click me</button>

JavaScript:

function sayHello() {
alert("Hello!");
}

You might also like