function sum(a, b) {
return a + b;
}
let result = sum(5, 3); // Chaqirish
console.log(result); // Natija: 8
coding with ☕️
function sum(a, b) { return a + b; } let result = sum(5, 3); // Chaqirish console.log(result); // Natija: 8
3. Return Qaytaruvchi Funksiya
let greet = function(name) {
return "Salom, " + name + "!";
};
console.log(greet("Hasan")); // Chaqirish
coding with ☕️
let greet = function(name) { return "Salom, " + name + "!"; }; console.log(greet("Hasan")); // Chaqirish
4. Anonim Funksiya (Function Expression)
const multiply = (a, b) => a * b;
console.log(multiply(4, 2)); // Chaqirish: 8
coding with ☕️
const multiply = (a, b) => a * b; console.log(multiply(4, 2)); // Chaqirish: 8
5. Arrow Function (ES6)
coding with ☕️
(function() { console.log("Bu funksiya avtomatik chaqiriladi!"); })();
6. Immediately Invoked Function Expression (IIFE)
const person = {
name: "Ali",
greet: function() {
console.log("Salom, men " + this.name);
}
};
person.greet(); // Chaqirish: Salom, men Aliconsole.log(${this.firstName} age is: ${age} );
}
firstPerson.convertAge(19)
secondPerson.convertAge(18)function Person(firstName, LastName ) {
this.firstName = firstName
this.LastName = LastName
this.isHuman = true
this.greeting = () => {
console.log(this);
}
}
const fistPerson = new Person("Fotima", "Nishonova")
console.log(fistPerson.greeting());function calc(number) {
return this * number
}
const double = calc.bind(2)
const trouble = calc.bind(3)
console.log(double(12));
console.log(double(24));
console.log(trouble(15));
console.log(trouble(30));
coding with ☕️
const calc = (a, b) => { b = b || 2 return a + b } console.log(calc(1, 10));
Rest opertaor method 1
coding with ☕️
const calc = (a, b = 2) => { return a + b } console.log(calc(1, 10));
Rest operator method 2