Untitled
user_7147158
plain_text
a year ago
1.5 kB
8
Indexable
// function
// parameter of a function
// rest parameter
// function hello(...a){
// console.log(a)
// }
// hello(1,2,3,4,5,6)
// arguments
// callback function
// function hey(){
// console.log("hey")
// }
// function hii(a){
// a()
// }
// hii(hey)
// passing a function as an argument to the function is known as callback function
// function greet(name, callback) {
// console.log('Hello, ' + name + '!');
// callback();
// }
// function sayGoodbye() {
// console.log('Goodbye!');
// }
// greet('Alice', sayGoodbye);
const arr = [1, 2, 3, 4, 5];
// let sum = 0;
// function addNum(index=0){
// if(arr.length === index){
// console.log(sum)
// }
// else{
// sum = sum + arr[index]
// index = index + 1;
// addNum(index);
// }
// }
// addNum();
function addNum(sum=0,index=0){
if(arr.length === index){
console.log(sum)
}
else{
sum = sum + arr[index];
index = index + 1;
addNum(sum,index);
}
}
addNum();
// const temp = [1,2,3,4,5,6,7,8];
// console.log(temp.length)
// do by recursion
// find the length of the array
// let sum1 = 1;
// function sum(){
// sum1 = sum1 + 1;
// console.log(sum1)
// }
// sum();
// sum();
// sum();
// sum();
// sum();
// default parameter
// function greet(a="wdwdw",b=2){
// console.log(a,b)
// }
// greet("11111111","2222222222222")
// greet()Editor is loading...
Leave a Comment