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!"}; }
);Forwarded from coding with ☕️
let userName = prompt("Your name?", "Alice");
let isTeaWanted = confirm("Do you want some tea?");
alert( "Visitor: " + userName ); // Alice
alert( "Tea wanted: " + isTeaWanted ); // trueForwarded from coding with ☕️
let isBoss = confirm("Are you the boss?");
alert( isBoss ); // true if OK is pressedForwarded from coding with ☕️
coding with ☕️
let isBoss = confirm("Are you the boss?"); alert( isBoss ); // true if OK is pressed
confirm operatorForwarded from coding with ☕️
let user = { // an object
name: "John", // by key "name" store value "John"
age: 30 // by key "age" store value 30
};Forwarded from coding with ☕️
function makeUser(name, age) {
return {
name: name,
age: age,
// ...other properties
};
}
let user = makeUser("John", 30);
alert(user.name); // JohnForwarded from coding with ☕️
let user = {
name: "John",
age: 30
};
user.sayHi = function() {
alert("Hello!");
};
user.sayHi(); // Hello!Forwarded from coding with ☕️
coding with ☕️
let user = { name: "John", age: 30 }; user.sayHi = function() { alert("Hello!"); }; user.sayHi(); // Hello!
the statement of Object get PropertyForwarded from coding with ☕️
let user = {
name: "John",
age: 30,
sayHi() {
// "this" is the "current object"
alert(this.name);
}
};
user.sayHi(); // JohnForwarded from coding with ☕️
coding with ☕️
let user = { name: "John", age: 30, sayHi() { // "this" is the "current object" alert(this.name); } }; user.sayHi(); // John
Object Property with "This Operator"Forwarded from coding with ☕️
let user = {
name: "John",
age: 30,
sayHi() {
alert(user.name); // "user" instead of "this"
}
};Forwarded from coding with ☕️
function BigUser() {
this.name = "John";
return { name: "Godzilla" }; // <-- returns this object
}
alert( new BigUser().name ); // Godzilla, got that object