+ Reply Thread
#1
Just variable coercion and scoping. This shouldn't be tricky if we really understand execution stack and how JS engine turns out to convert two primitives when there are added or concatenated.

Before you run the code in your console, try and provide answers to the logs from 1 to 10 they will help you become a better JS dev.

And more like these will keep coming as I unraveled them in more future readings and experiments

Code below, remember answer first before running:

Code:
this.name = 'aleem'; function logName () { this.name = 'limistah'; console.log('First log', this.name); logAgain(); function logAgain() { this.name = 'randomUser'; console.log('Second Log', this.name); } } logName(); console.log('Third log', NaN === NaN); console.log('Fourth log', typeof null); console.log('Fifth log', 1 + '2' +3); console.log('Sixth log', 1 + 2 + 3); console.log('Seventh log', 1 + 2 + '3'); function retFunc () { console.log('in return function'); var name = 'Test 1'; return function (greeting) { return (greeting + ' ' + this.name); } } console.log('Eight log', retFunc()('Hi')); console.log('Ninth log', retFunc().apply(this, ['Hello'])); obj = { name: 'randomTester' } console.log('Tenth log', retFunc().call(obj, ['Hey']));
#2
Lemme try
.
.
1. First log,limistah;
2. Second log, random user;
3. Third log,true;
4. ???
5. 15;
6. 5
7. 33;
8. ??
9. Hello allen;
10. ??
#3
You've really tried. But some of them are wrong. Try running the code and compare the result with your answer.
#4
I didn't run d code.....but I would correct my mistakes when I do
#5
I didn't run d code.....but I would correct my mistakes when I do
Back to top