JAVASCRIPT NECESSITIES(things you need to emphasis on):
Jane49-cloud
Posted on December 22, 2022
1.Variables: Variables are used to store and manipulate data in JavaScript. You can create a variable using the var, let, or const keyword.
let x = 5;
console.log(x); // Output: 5
2.Data types: JavaScript has several data types, including numbers, strings, booleans, and objects.
let num = 5; // number
let str = 'Hello'; // string
let bool = true; // boolean
let obj = {key: 'value'}; // object
3.Arrays: Arrays are used to store lists of data in JavaScript. You can access and modify the elements of an array using their index.
let arr = [1, 2, 3, 4, 5];
console.log(arr[2]); // Output: 3
arr[2] = 10;
console.log(arr); // Output: [1, 2, 10, 4, 5]
4.Loops: Loops allow you to repeat a block of code multiple times. There are several types of loops in JavaScript, including for loops and while loops.
for (let i = 0; i < 5; i++) {
console.log(i); // Output: 0 1 2 3 4
}
let j = 0;
while (j < 5) {
console.log(j); // Output: 0 1 2 3 4
j++;
}
5.Functions: Functions are blocks of code that can be called by their name. They can also accept arguments and return a value.
function add(x, y) {
return x + y;
}
console.log(add(2, 3)); // Output: 5
6.Objects: Objects are collections of key-value pairs in JavaScript. You can access and modify the values of an object using its keys.
let obj = {
key1: 'value1',
key2: 'value2'
};
console.log(obj.key1); // Output: 'value1'
obj.key1 = 'new value';
console.log(obj.key1); // Output: 'new value'
7.Destructuring: Destructuring is a feature of JavaScript that allows you to extract values from arrays and objects into variables.
let arr = [1, 2, 3];
let [x, y, z] = arr;
console.log(x); // Output: 1
console.log(y); // Output: 2
console.log(z); // Output: 3
let obj = {key1: 'value1', key2: 'value2'};
let {key1, key2} = obj;
console.log(key1); // Output: 'value1'
console.log(key2); // Output: 'value2'
8.Spread operator: The spread operator allows you to spread the elements of an array or object into a new array or object.
let arr1 = [1, 2, 3];
let arr2 = [...arr1, 4, 5];
console.log(arr2); // Output: [1, 2, 3, 4, 5]
let obj1 = {key1:
9 Map method: The map method is a higher-order function that allows you to transform the elements of an array. It returns a new array with the transformed elements.
let arr = [1, 2, 3];
let newArr = arr.map(x => x * 2);
console.log(newArr); // Output: [2, 4, 6]
10.Set method: The Set object is a collection of unique values. You can use the add method to add values to a Set, and the has method to check if a value is in a Set.
let set = new Set();
set.add(1);
set.add(2);
set.add(3);
console.log(set.has(1)); // Output: true
console.log(set.has(4)); // Output: false
Posted on December 22, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.