Default Function Argument Flashcards
1
Q
Explain how default arguments are in functions
A
You can make the arguments equal a certain value
function User(id){ this.id = id; }
function generateId(){ return Math.random() \* 9999999; }
function createAdminUser(user = new User(generateId())){ user.admin = true; return user; }
const user = new User(generateId()); createAdminUser(user);