Skip to content

Instantly share code, notes, and snippets.

@kowsheek
Last active February 15, 2018 15:52
Show Gist options
  • Save kowsheek/86685fc36d143941e2b41265ee7cc59b to your computer and use it in GitHub Desktop.
Save kowsheek/86685fc36d143941e2b41265ee7cc59b to your computer and use it in GitHub Desktop.
function sum(x, y) {
return (x + y);
}
console.log('sum', sum(10, 20));
function addsFive(x) {
function a(y) {
return (x + y) + 5;
};
function b(z) {
return (x + z) + 5;
};
return a(10) + b(20);
}
var result = addsFive(30);
console.log(result);
function addsFive(x) {
return function (y) {
return (x + y) + 5;
};
}
var first = addsFive(10);
console.log(first.toString());
var second = first(20, 40);
console.log(second);
function welcome(firstName, lastName) {
function addHello(firstName) {
return 'Hello ' + firstName + '!\n';
};
function addWelcome(area) {
return 'Welcome to ' + area + '.';
};
return function(area) {
return addHello(firstName) + addWelcome(area);
};
}
var welcoming = welcome('Jack', 'Belly');
console.log(welcoming('Toronto'));
console.log('\n');
console.log(welcoming('Montreal'));
function sum(x, y) {
return (x + y);
}
function multiply(x, y) {
var mySum = 0;
for (var i = 0; i < x; i++) {
mySum = sum(y, y);
}
console.log(mySum);
return (x * y);
}
console.log('sum', sum(10, 20));
console.log('multiply', multiply(10, 20));
1. Reading code
- Instructions
- Inputs
- Variables
- Outputs
2. Scopes
- Global scope
- Local scope
- Chaining scopes
3. Functions
- The nature of functions
- Basics of functions
- Nesting functions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment