Question
Which ES6 feature allows for function parameters to have
default values if no value is provided during a function call?Solution
Default parameters in ES6 enable a function to use a default value for a parameter if no argument is passed. This enhances code readability and reduces the need for conditional checks. Example: function greet(name = "Guest") { Â return `Hello, ${name}!`; } console.log(greet());Â Â Â Â Â Â // Outputs: Hello, Guest! console.log(greet("Alice"));Â Â // Outputs: Hello, Alice! This feature is especially useful in scenarios where optional parameters are involved, as it simplifies function declarations. ________________________________________ Why Other Options Are Incorrect: 1. Arrow functions: Arrow functions are a concise syntax for writing functions but do not relate to parameter defaults. 2. Template literals: Template literals allow embedding expressions in strings using backticks, unrelated to parameter handling. 3. Rest parameters: Rest parameters gather multiple arguments into an array, enabling flexible argument handling but do not assign defaults. 4. Destructuring assignment: Destructuring allows unpacking values from arrays or objects but does not deal with function defaults.
The cost price of an article is 30% less than its selling price. For how much profit was it sold? (Round off up to 2 decimal plac...
A shopkeeper sold an article after giving a discount of 20% and made a profit of Rs.40. Find the difference between the marked price and selling price o...
When an item is sold for Rs. 800, the profit is 10% more than when it's sold for Rs. 780. To achieve a 60% profit, determine the selling price.
Raghav sold two items, 'A' and 'B', each for Rs. 2,000. He incurred a 20% loss on item 'A' and earned a 25% profit on item 'B'. Calculate the approximat...
Cost price of an article A is Rs. 400 less than that of B. A and B are marked 40% and 20% above their cost price respectively. A and B are sold after a...
- If the total cost of 9 mangoes and 6 oranges is Rs. 270 and the total cost of 7 mangoes and 4 oranges is Rs. 200, then find the cost of 5 mangoes.
The selling price of y items is equal to the cost price of 720 items. If the profit made is 60%, then find the value of y.
A sold a watch to B at a profit of 20%. B sold it to C at 30% profit. C sold it to D at 10% loss. If B's profit is ₹.80 more than that of A, then D bo...
- Ramesh made a profit of 30% on an article, while Suresh sold the same article for a 22% profit. If Ramesh’s profit was Rs. 54 more than Suresh’s profit...
Profit percentage received on a product when sold for Rs.560 is equal to the percentage loss incurred when the same product is sold for Rs.420. Find the...