Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var square = function(x) { // assign a function to a variable square that has one parameter, x.
- return x * x;
- };
- console.log(square(12)); // invoke square function, with 12 as the argument.
- // 144
- var shape = "square";
- var MyFavoriteShape = function() { // this function is not using any parameter
- return shape;
- }
- console.log(MyFavoriteShape());
- // square
- var multiplyThreeNumbers = function (x,y,z) { // a function with three parameters
- return x * y * z;
- }
- console.log(multiplyThreeNumbers(2,3,4));
- // 24
- var Me = {
- name: "Glendon Philipp Baculio",
- age: 22,
- };
- var UseAnObjectParameter = function(xyz) { // assign an object parameter
- return "name: "+ xyz.name + " age: "+xyz.age;
- }
- console.log(UseAnObjectParameter(Me));
- var addTwo = function(x) {
- if(isNaN(x)) {
- return;
- }
- return x+2;
- }
- console.log(ReturnUndefinedIfxIsNotAnumberOrFalsy());
- //undefined
- console.log(ReturnUndefinedIfxIsNotAnumberOrFalsy("x"));
- //undefined
- console.log(ReturnUndefinedIfxIsNotAnumberOrFalsy(2));
- //4
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement