Advertisement
Guest User

Untitled

a guest
Sep 20th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. // 57: Default parameters - basics
  2. // To do: make all tests pass, leave the assert lines unchanged!
  3. // Follow the hints of the failure messages!
  4.  
  5. describe('Default parameters make function parameters more flexible', () => {
  6. it('define it using an assignment to the parameter `function(param=1){}`', function() {
  7. let number = (int = 0) => int;
  8. assert.equal(number(), 0);
  9. });
  10. it('it is used when `undefined` is passed', function() {
  11. let number = (int = 23) => int;
  12. const param = undefined;
  13. assert.equal(number(param), 23);
  14. });
  15. it('it is not used when a value is given', function() {
  16. function xhr(method) {
  17. return method;
  18. }
  19. assert.equal(xhr('POST'), 'POST');
  20. });
  21. it('it is evaluated at run time', function() {
  22. let defaultValue = 42;
  23. function xhr(method = `value: ${defaultValue}`) {
  24. return method;
  25. }
  26. assert.equal(xhr(), 'value: 42');
  27. });
  28. it('it can also be a function', function() {
  29. const defaultValue = (ok) => defaultValue;
  30. function fn(value = defaultValue) {
  31. return value;
  32. }
  33. assert.equal(fn(), 'defaultValue');
  34. });
  35. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement