param1
y param2
: función testFun (param1, param2) {Luego podemos llamar a
console.log (param1, param2);
}
testFun
: testFun("Hello", "World");
Hemos pasado dos argumentos, "Hello"
y "World"
. Dentro de la función, param1
será igual a "Hello" y param2
será igual a "World". Tenga en cuenta que podría testFun
llamar a testFun
con diferentes argumentos y los parámetros tomarían el valor de los nuevos argumentos. functionWithArgs
que acepte dos argumentos y envíe su suma a la consola dev. functionWithArgs
debería ser una función
testString: 'assert(typeof functionWithArgs === "function", "functionWithArgs
should be a function");'
- text: 'functionWithArgs(1,2)
debe generar 3
'
testString: 'if(typeof functionWithArgs === "function") { capture(); functionWithArgs(1,2); uncapture(); } assert(logOutput == 3, "functionWithArgs(1,2)
should output 3
");'
- text: 'functionWithArgs(7,9)
debe dar salida a 16
'
testString: 'if(typeof functionWithArgs === "function") { capture(); functionWithArgs(7,9); uncapture(); } assert(logOutput == 16, "functionWithArgs(7,9)
should output 16
");'
- text: Llame a functionWithArgs
con dos números después de definirlo.
testString: 'assert(/^\s*functionWithArgs\s*\(\s*\d+\s*,\s*\d+\s*\)\s*;/m.test(code), "Call functionWithArgs
with two numbers after you define it.");'
```