Mastering JavaScript Fundamentals: A Starter's Handbook


for..in v/s for...of:
By using the for..in i get the indexes only but with the help of those indexes i can get the values at that index.
By using the for...of I can only get the value only values directly I don’t get the indexes.
<script>
let arr=["apple","banana","guava"];
for(i in arr){
document.writeln(`index=${i}`);
document.writeln(`value=${arr[i]});
}
for(i of arr)
{
document.writeln('value=${i}`);
}
</script>
Here we can observe the differences easily
for of vs for Each()
for of will works for Arrays, strings, maps, sets but for each will works Arrays only .
foreach always need the callback function
Functions in JavaScript
Function with parameter and return type.
Function with default Parameter
function greet(name="alice")
{
document.writeln(" Hii "+ name);
}
greet();// Hii alice
greet("Vaishu"); // Hii vaishu
let’s discuss arrow functions in detail
Arrow Functions
Arrow function is shorter way to write a function in JavaScript
it uses the => symbol instead of function keyword.
Callback Function
It is simply a function that is passed as argument to another function
callback adds the extra functionality to function and control the order of execution
<script>
function before(c)
{
for(let k=0;k<10;k++){
console.log(k)
c(k);
}
}
function c(n)
{
console.log(` number ${n}`)
}
before(c)
</script>
What is splice and slice in JavaScript🤔
Slice()
Extracts a portion of array or string without modifying the original
syntax
array. slice(start, end);
here the end is not included
splice()
changes the original array by removing, adding, replacing.
array. splice(start,deletecount,item1,item2…);
Subscribe to my newsletter
Read articles from GAJULA VAISHNAVI directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

GAJULA VAISHNAVI
GAJULA VAISHNAVI
I am aspiring full stack java developer