Explorer
Node.js

Write a function `getUserInfo(user)` that destructures `name`, `age`, and `role` (default: `"user"`) from the object and returns a formatted string: `"name (age) - role"`.

Problem Statement

Write a function `getUserInfo(user)` that destructures `name`, `age`, and `role` (default: `"user"`) from the object and returns a formatted string: `"name (age) - role"`.

Complexity

Time Complexity: -

Space Complexity: -

Hints

šŸ’” Hint 1: Object destructuring: const { name, age } = obj. šŸ’” Hint 2: You can set default values: const { role = "user" } = obj. šŸ’” Hint 3: Use template literals to format the string. āœ… Solution: ```javascript function getUserInfo(user) { const { name, age, role = "user" } = user; return `${name} (${age}) - ${role}`; } ```

Object Destructuring with Defaults

Easy
Write a function `getUserInfo(user)` that destructures `name`, `age`, and `role` (default: `"user"`) from the object and returns a formatted string: `"name (age) - role"`.
Editor
Loading Editor...
Evaluate code
Output:Click "Run" above to execute and verify your code here.
["Alice (30) - admin","Bob (25) - user"]