Forwarded from coding with ☕️
let func = function(arg1, arg2, ..., argN) {
return expression;
};Forwarded from coding with ☕️
coding with ☕️
Function Declaration (An'anaviy Funksiya)
function sayHello() {
console.log("Hello!");
}
sayHello(); // "Hello!"Forwarded from coding with ☕️
coding with ☕️
Function Expression (Ifodaviy Funksiya)
const sayHello = function() {
console.log("Hello!");
};
sayHello(); // "Hello!"Forwarded from coding with ☕️
coding with ☕️
Arrow Function (Yoyuvchi Funksiya)
const sayHello = () => {
console.log("Hello!");
};
sayHello(); // "Hello!"Forwarded from coding with ☕️
Qisqa yozuv: {} va return ni olib tashlash mumkin.Forwarded from coding with ☕️
coding with ☕️
Qisqa yozuv: {} va return ni olib tashlash mumkin.
const add = (a, b) => a + b;
console.log(add(2, 3)); // 5
Forwarded from coding with ☕️
coding with ☕️
Constructor Function (Konstruktor Funksiya)
function Person(name, age) {
this.name = name;
this.age = age;
}
const person1 = new Person("Ali", 25);
console.log(person1.name); // "Ali"Forwarded from coding with ☕️
Immediately Invoked Function Expression (IIFE)Forwarded from coding with ☕️
coding with ☕️
Immediately Invoked Function Expression (IIFE)
(function() {
console.log("This runs immediately!");
})();Forwarded from coding with ☕️
coding with ☕️
Generator Function (Generator Funksiya)
function* generator() {
yield 1;
yield 2;
yield 3;
}
const gen = generator();
console.log(gen.next().value); // 1
console.log(gen.next().value); // 2Forwarded from coding with ☕️
function ask(question, no, yes){
if(confirm(question))yes()
else no()
}
ask("do you agere?"
function(){alert{"You agreed!"}; },
function(){alert{"You canceled the execution!"}; }
);