Labels
In this lesson, we'll explore labeled parameters and why they are useful.
We'll cover the following...
The Position of a Parameter
So far in the course, the arguments in a function have had fixed positions. In other words, the order of inputs must be maintained when calling the function.
Here’s an example:
Press + to interact
type superhero = {realName: string,heroName: string};let createHero = (realName, heroName) => {realName,heroName};let real = "Bruce Wayne";let hero = "Batman";/* Correct Order */let correctBatman = createHero(real, hero);Js.log(correctBatman);/* Incorrect Order */let incorrectBatman = createHero(hero, real);Js.log(incorrectBatman);
In line 19, we reversed the order of our parameters, however, since the function was defined with the first ...