πJavascript Basics
Last updated
Last updated
// Variables
var myVariable = "Hello, World!";
let anotherVariable = 42;
const pi = 3.14;
// Data Types
let str = "String";
let num = 42;
let bool = true;
let arr = [1, 2, 3];
let obj = { key: "value" };let a = 5;
let b = 10;
// Arithmetic operators
let sum = a + b;
let difference = a - b;
let product = a * b;
let quotient = a / b;
// Comparison operators
let isEqual = a === b;
let isNotEqual = a !== b;
let greaterThan = a > b;
let lessThan = a < b;
// Logical operators
let andOperator = true && false;
let orOperator = true || false;
let notOperator = !true;let x = 10;
if (x > 0) {
console.log("Positive");
} else if (x < 0) {
console.log("Negative");
} else {
console.log("Zero");
}// For loop
for (let i = 0; i < 5; i++) {
console.log(i);
}
// While loop
let j = 0;
while (j < 5) {
console.log(j);
j++;
}function greet(name) {
console.log("Hello, " + name + "!");
}
greet("John");// Arrays
let fruits = ["apple", "banana", "orange"];
// Objects
let person = {
name: "John",
age: 25,
isStudent: false
};