javascript sources
1 subscriber
1 photo
1 link
Hello world
Download Telegram
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 ☕️
Generator Function (Generator Funksiya)
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); // 2
Forwarded 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 ); // true
Forwarded from coding with ☕️
let isBoss = confirm("Are you the boss?");

alert( isBoss ); // true if OK is pressed
Forwarded from coding with ☕️
Object
Forwarded 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); // John
Forwarded from coding with ☕️
let user = {
name: "John",
age: 30
};

user.sayHi = function() {
alert("Hello!");
};

user.sayHi(); // Hello!
Forwarded from coding with ☕️
let user = {
name: "John",
age: 30,

sayHi() {
// "this" is the "current object"
alert(this.name);
}

};

user.sayHi(); // John
Forwarded from coding with ☕️
let user = {
name: "John",
age: 30,

sayHi() {
alert(user.name); // "user" instead of "this"
}

};
Forwarded from coding with ☕️
function sayHi() {
alert( this.name );
}
Forwarded from coding with ☕️
function BigUser() {

this.name = "John";

return { name: "Godzilla" }; // <-- returns this object
}

alert( new BigUser().name ); // Godzilla, got that object