Advertisement
Guest User

Untitled

a guest
Apr 28th, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. var square = function(x) { // assign a function to a variable square that has one parameter, x.
  2. return x * x;
  3. };
  4. console.log(square(12)); // invoke square function, with 12 as the argument.
  5. // 144
  6.  
  7. var shape = "square";
  8. var MyFavoriteShape = function() { // this function is not using any parameter
  9. return shape;
  10. }
  11. console.log(MyFavoriteShape());
  12. // square
  13.  
  14. var multiplyThreeNumbers = function (x,y,z) { // a function with three parameters
  15. return x * y * z;
  16. }
  17. console.log(multiplyThreeNumbers(2,3,4));
  18. // 24
  19.  
  20. var Me = {
  21. name: "Glendon Philipp Baculio",
  22. age: 22,
  23. };
  24. var UseAnObjectParameter = function(xyz) { // assign an object parameter
  25. return "name: "+ xyz.name + " age: "+xyz.age;
  26. }
  27. console.log(UseAnObjectParameter(Me));
  28.  
  29. var addTwo = function(x) {
  30. if(isNaN(x)) {
  31. return;
  32. }
  33. return x+2;
  34. }
  35. console.log(ReturnUndefinedIfxIsNotAnumberOrFalsy());
  36. //undefined
  37. console.log(ReturnUndefinedIfxIsNotAnumberOrFalsy("x"));
  38. //undefined
  39. console.log(ReturnUndefinedIfxIsNotAnumberOrFalsy(2));
  40. //4
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement