├── README.md └── interview-exercises.md /README.md: -------------------------------------------------------------------------------- 1 | # js-exercises 2 | Some javascript exercises for learning by doing 3 | -------------------------------------------------------------------------------- /interview-exercises.md: -------------------------------------------------------------------------------- 1 | ### Scope 2 | 3 | ```javascript 4 | (function() { 5 | var a = b = 5; 6 | })(); 7 | 8 | console.log(b); 9 | ``` 10 | 11 | What will be printed on the console? 12 | 13 | ### Hoisting 14 | 15 | What’s the result of executing this code and why. 16 | 17 | ```javascript 18 | function test() { 19 | console.log(a); 20 | console.log(foo()); 21 | 22 | var a = 1; 23 | function foo() { 24 | return 2; 25 | } 26 | } 27 | 28 | test(); 29 | ``` 30 | ### this 31 | What is the result of the following code? Explain your answer. 32 | 33 | ```javascript 34 | var fullname = 'John Doe'; 35 | var obj = { 36 | fullname: 'Colin Ihrig', 37 | prop: { 38 | fullname: 'Aurelio De Rosa', 39 | getFullname: function() { 40 | return this.fullname; 41 | } 42 | } 43 | }; 44 | ``` 45 | 46 | How old is Juan ? 47 | 48 | ```javascript 49 | 50 | function Person(age) { 51 | this.age = age 52 | this.grow = function () { 53 | this.age++; 54 | } 55 | this.rejuvenate = function () { 56 | this.age--; 57 | } 58 | } 59 | 60 | var juan = new Person(18) 61 | $button.on('click', juan.grow); 62 | $button.click(); 63 | 64 | juan.rejuvenate(); 65 | 66 | console.log(juan.age) // ? 67 | ``` 68 | --------------------------------------------------------------------------------