Javascript
// Declare variables with different data types
let numberVar = 10;
let stringVar = "Hello";
let booleanVar = true;
let arrayVar = [1, 2, 3];
let objectVar = { name: "John", age: 30 };
// 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
Manipulating Data in Arrays
Fetching Data:
To fetch data from an array, you can use indexing.
let fruits = ["Apple", "Banana", "Orange"];
console.log(fruits[0]); // Output: Apple
console.log(fruits[1]); // Output: Banana
Editing Data:
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.
fruits.splice(1, 1); // Removes 1 element at index 1
console.log(fruits); // Output: ["Apple", "Orange"]
Manipulating Data in Objects
Fetching Data:
To fetch data from an object, you can use dot notation or bracket notation.
let person = {
name: "John",
age: 30,
city: "New York"
};
console.log(person.name); // Output: John
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;
console.log(person); // Output: {name: "John", age: 31, city: "New York"}
Deleting Data:
To delete a property from an object, you can use the delete operator.
delete person.city;
console.log(person); // Output: {name: "John", age: 31}