Javascript (JS) Notes
Javascript (JS) Notes
// Print variables
console.log(numberVar, stringVar, booleanVar);
console.log(arrayVar[0]); // Access array element
console.log(objectVar.name); // Access object property
OR
// Declare variables with different data types
let a = 10;
let b = "Hello";
let c = true;
let d = [1, 2, 3];
let e = { name: "John", age: 30 };
// Print variables
console.log(a, b, c);
console.log(d[0]); // Access array element
console.log(e.name); // Access object property
Operators:
let a = 10;
let b = 5;
// Arithmetic operators
console.log(a + b); // Addition Result : 15
console.log(a - b); // Subtraction Result : 5
console.log(a * b); // Multiplication Result :50
console.log(a / b); // Division Result : 2
// Comparison operators
console.log(a > b); // Greater than Result : true
console.log(a === b); // Equal to (strict) Result : false
console.log(a !== b); // Not equal to Result : true
// Logical operators
console.log(a > 5 && b < 10); // AND Result : true
console.log(a > 5 || b < 2); // OR Result : true
console.log(!a); // NOT Result : false
You can edit data in an array by accessing the specific index and assigning a new value.
fruits[1] = "Mango";
console.log(fruits); // Output: ["Apple", "Mango", "Orange"]
Deleting Data:
To delete data from an array, you can use the splice method.
To fetch data from an object, you can use dot notation or bracket notation.
let person = {
name: "John",
age: 30,
};
console.log(person["age"]); // Output: 30
Editing Data:
To edit data in an object, you can directly assign new values to the properties.
person.age = 31;
Deleting Data:
To delete a property from an object, you can use the delete operator.
delete person.city;