Passing Options by Name
Python’s quote_line() takes a rush flag and passes it on with quote(words, rush=rush), and its caller writes
quote_line("Bauer Legal", 6200, rush=True): Bauer Legal: €1,116.00, 2 working days.
The line-by-line JavaScript port keeps both keyword calls, and it stops at the bottom one with
ReferenceError: rush is not defined, a message about a variable, not an argument. Passing
true by position instead runs, but prints Bauer Legal: €6,200.00, 5 working days.
- JavaScript has no keyword arguments. In a call,
name = valueis an assignment, an expression with a value, so it can sit where an argument goes. - At the bottom,
rushwas never declared, and an ES (ECMAScript) module runs in strict mode, where that’s an error, not a quiet new global. - Inside
quoteLine(),rushis a parameter, sorush = rushassigns it to itself. Its value,true, isquote()’s second argument,rate:6200 * trueis6200, andrushkeeps its default, so five days. Python’squote(6200, True)gives(6200, 5)too: what JavaScript lacks is the name.
When a call needs names, pass one object. Before each colon is the option’s name, written bare,
as in Python’s rush=rush: it’s the name itself, never a variable. The function takes the object apart in its parameter list
with a destructuring pattern: