Named exports are also distinct in that they can be exported as soon as they are declared, by placing the keyword export
in front of variable declarations.
In menu.js
export let specialty = ''; export function isVegetarian() { }; function isLowSodium() { };
- The
export
keyword allows us to export objects upon declaration, as shown inexport let specialty
andexport function isVegetarian() {}
. - We no longer need an
export
statement at the bottom of our file, since this behavior is handled above.
Instructions
Let’s add some additional data to our airplane.js file.
Continue by adding more data to objects within the availableAirplanes
variable.
To the first object AeroJet, add a property maxSpeed
with a value of 1200
and a property minSpeed
with a value of 300
.
To the second object SkyJet, add a property maxSpeed
with a value of 800
and a property minSpeed
with a value of 200
.
Within the flightRequirements
object, add a property requiredSpeedRange
and set this equal to 700
.
Continuing with the same file, add a new function meetsSpeedRangeRequirements()
that takes three arguments maxSpeed
, minSpeed
and requiredSpeedRange
.
Within the meetsSpeedRangeRequirements
function, create a variable range
, and set it to the difference between maxSpeed
and minSpeed
.
In the body of the meetsSpeedRangeRequirements()
function, create logic to check if the range
is greater than the requiredSpeedRange
.
The function should contain this logic:
if the `range` is greater than the `requiredSpeedRange` return true else return false
Use export
to export the variables as soon as they are declared, and remove the export
statement at the bottom of the file.