An Interest In:
Web News this Week
- April 19, 2024
- April 18, 2024
- April 17, 2024
- April 16, 2024
- April 15, 2024
- April 14, 2024
- April 13, 2024
JAVASCRIPT NECESSITIES(things you need to emphasis on):
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; // numberlet str = 'Hello'; // stringlet bool = true; // booleanlet 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: 3arr[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: 1console.log(y); // Output: 2console.log(z); // Output: 3let 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: trueconsole.log(set.has(4)); // Output: false
Original Link: https://dev.to/jane49cloud/javascript-necessitiesthings-you-need-to-emphasis-on-1dn1
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To