Skip to content

Instantly share code, notes, and snippets.

@martpie
Last active January 19, 2018 12:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martpie/c4d92980454daf5f90ba22aa6beec55c to your computer and use it in GitHub Desktop.
Save martpie/c4d92980454daf5f90ba22aa6beec55c to your computer and use it in GitHub Desktop.
Small JS exercises
/**
* Small JS exercices
* Consider all exercises independant from each other and running in their own scope
*
*/
/**
* What is the output of this piece of code?
*
*/
console.log(0);
setTimeout(() => { console.log(1) }, 2000);
setTimeout(() => { console.log(2) }, 0);
console.log(3);
/**
* What is the output of this piece of code?
*
*/
console.log(a);
a = 1;
console.log(a);
function a() {
console.log(2)
}
console.log(a)
/**
* Implement a mini-event library
*
*/
minievent.on('test', () => {
console.log('That is an event');
});
minievent.emmit('test');
function minievent() {
// ...
this.on = () => {
// ...
}
this.emit = () => {
// ...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment