Skip to content

Instantly share code, notes, and snippets.

View srijoy-paul's full-sized avatar
:shipit:
Learning

Srijoy Paul srijoy-paul

:shipit:
Learning
View GitHub Profile
  • Anonymous functions in JavaScript, are the functions that do not have any name.
  • Anonymous functions(reference) are stored in variables. They are always invoked (called) using the variable name.
  • We can write an anonymous function using the function keyword, followed by parentheses (param1,param2,...) and then the curly braces, the same as we do for normal functions in any language.
  • Some important use cases:
    • Anonymous functions are used a lot as callback functions.
    • It's useful when we want any function to be invoked right after it is declared.
    • It is used a lot, for different eventhandlers in js.
    • It's more useful, when a function is to be used only once.
  • There is another type of function in JS which can be called as a type of anonymous function, Which is the Arrow Fucntions:
  • => is the representation for arrow functions.
console.log("Starting Game ..");
let rand;
let player;
let player_choice;
let computer;
let response;
let rounds = prompt("Number of rounds you want to play?");
for (let i = 1; i <= rounds; i++) {