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.
A cube of side 14 cm is immersed completely in a cylindrical vessel of radius 10 cm. What will be the rise in the water level in the vessel due to the i...
Calculate the area of a circular field whose circumference is equal to the perimeter of a rectangular field with a length of 60 m and a breadth of 45 m....
If the area of a rhombus is 18954 m² and the ratio of the diagonals is 27: 39, then find the length of the shorter diagonal.
The surface area of the two spheres are in the ratio 4:9. Their volumes will be in the ratio.
The diameter of the base of a cylindrical drum is 14 cm and its height is 12 cm. The drum is full of water and the water from the drum is transferred to...
Four circles of equal radii are described about the four corners of a square so that each touches two of the other circles. If each side of the square i...
The difference between the length and breadth of a rectangle is 19 m. If its perimeter is 198 m, then its area is
The cost of fencing a square plot @ Rs.16/m is Rs. 2304. What will be the cost of flooring the plot @ Rs. 3.5/ square m?
The measure of an angle is one-third of its supplementary angle. Find its measure.