JavaScript adalah bahasa pemrograman yang digunakan untuk membuat halaman web interaktif. Berikut adalah beberapa konsep dasar dalam JavaScript:
var x = 5;
let y = 10;
const z = 15;
console.log(`x : ${x}`)
console.log(`y : ${y}`)
console.log(`z : ${z}`)
let name = "John";
let age = 30;
let isStudent = true;
console.log(`name : ${name}`)
console.log(`age : ${age}`)
console.log(`isStudentt : ${isStudent}`)
function greet(name) {
return "Hello, " + name + "!";
}
let greeting = greet("World");
let x = 10
if (x > 0) {
console.log("Positif");
} else {
console.log("Negatif");
}
for (let i = 0; i < 5; i++) {
console.log(i);
}
let person = {
name: "John",
age: 30,
isStudent: true
};
let numbers = [1, 2, 3, 4, 5];
let fruits = ["Apple", "Banana", "Orange"];
document.getElementById("myButton").addEventListener("click",
function() {
console.log("Button clicked");
});
let xhr = new XMLHttpRequest();
xhr.open("GET", "https://api.example.com/data", true);
xhr.send();
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200) {
console.log(xhr.responseText);
}
};