- 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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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++) { |