js map
js map
function calculateTax(cost,tax){
taxamt = cost*(tax/100)
console.log('Total cost is : ${cost}
GST of tax($(tax}%) is: $(taxamt}
Total amount is : ${ cost+tax})
calculateTax(45,12);
function calculateTax(cost,tax){
tax = tax ?? 18;
taxamt = cost*(tax/100)
console.log('Total cost is : ${cost}
GST of tax($(tax}%) is: $(taxamt}
Total amount is : ${ cost+tax})
calculateTax(45);
taxamt = cost*(tax/100)
console.log('Total cost is : ${cost}
GST of tax($(tax}%) is: $(taxamt}
Total amount is : ${ cost+tax})
calculateTax(45);
Reference types:
Reference types are data types that store a reference to a value, rather than the actual value itself.
When a variable is assigned a reference type, it stores a reference to the value in memory, rather
than the value itself. This means that changes made to the variable affect the original value.
The most common examples of reference types in JavaScript are objects and arrays.
Object: This reference type stores a collection of key-value pairs and is defined using curly
braces { }.
Array: This reference type stores a collection of values and is defined using square brackets [ ].
When a reference type is passed as an argument to a function, a reference to the original value is
passed to the function, rather than a copy of the value. This means that changes made to the
value within the function affect the original value.
Pass-by-Value
When you pass a variable of a primitive data type as an argument to a function, a copy of the
variable's value is created and passed to the function. Any changes made to the copy inside the
function do not affect the original variable outside the function.
Example
function double(number) {
number = number * 2;
return number;
}
let num = 5;
let doubledNum = double(num);
console.log(num); // Output: 5
console.log(doubledNum); // Output: 10
Pass-by-Reference
In JavaScript, objects and arrays are passed by reference. This means that when you pass an
object or an array to a function, any changes made to the object or array inside the function also
affect the original object or array outside the function.
Passing Objects
In JavaScript, objects are passed into functions by reference. This means that when an object is
passed into a function, any changes made to the object inside the function will also affect the
original object outside the function. This is because the object reference is being passed, not the
object itself.
function updatePerson(obj) {
obj.age = 31;
}
updatePerson(person);
console.log(person.age); // Output: 31
A JavaScript Set object is a collection of unique values. Each value can only occur once in a Set.
A Set can hold any value of any data type
Sets can only hold unique values, while Arrays can hold duplicate values.
Sets are not ordered, while Arrays are ordered.
Sets are faster to add and remove items from than Arrays.
Syntax
let set1 = new Set([iterable]);
Example
Let arr = [1,1,2,3,4,5,5,5,10,8]
Let myset1 = new Set(arr)
console.log(arr)
console.log(myset1)
console.log(myset2)
let ob = {‘a’:1,’b’:2}
myset.add(obj)
console.log(myset2)
console.log(myset2.sieze)
console.log(myset2.has(6))
console.log(myset2.delete(4))
Map
Map objects are collections of Key-value pairs
A key in the map may only occur once
Key or value can be object
Third-party APIs
The third-party API allows you to get the data from their web servers. For example, YouTube
API allows you to get the data from YouTube’s web server.
list of common third-party APIs.
YouTube API − It allows you to get YouTube videos and display them on the website.
Facebook API − It allows you to get Facebook posts and display them on the website.
Telegram API − It allows you to fetch and send messages to the telegram.
Twitter API − It allows you to get tweets from Twitter.
Pinterest API − It allows you to get Pinterest posts.