Javascript Coding Interview Questions | Advanced Javascript Interview Questions

  Рет қаралды 15,286

Monsterlessons Academy

Monsterlessons Academy

Күн бұрын

Пікірлер: 48
@MonsterlessonsAcademy
@MonsterlessonsAcademy 3 жыл бұрын
WATCH NEXT: Javascript Interview Questions and Answers - Dominate Your Next Interview - kzbin.info/www/bejne/rZ-8fHtombRpaJIsi=5DfbGEfhXWiiv0a_
@bogujang9
@bogujang9 Жыл бұрын
Please mark missleading explanation at 11:42 as it might confuse others. Return is missing. Also interesting to mention if you have regular object (not an instance of a class), you actually get undefined with arrow func: var a = { prop: 'hi', a1: () => this.prop, a2: function () {return this.prop} } a.a1() // undefined a.a2() // 'hi'
@KAZVorpal
@KAZVorpal 5 ай бұрын
He got MANY details wrong. I wonder if he's caused some people to fail coding interviews.
@anasouardini
@anasouardini Жыл бұрын
This works just fine (prints "lll"), because I didn't forget `return`: class p { constructor (name){ this.name = name; } b = function(){ return this.name } } const c = new p('lll') console.log(c.b())
@KAZVorpal
@KAZVorpal 5 ай бұрын
You're wrong about let, const, and arrow functions not hoisting. They ARE hoisted. They just aren't hoisted the same way. let and const are hoisted, but put in a "temporal dead zone" until declared. So you don't get "undefined", but you do get "reference error", because the interpreter does know they exist. And arrow functions are also hoisted. In fact, their hoisting is based on how you declare them. Most people declare them with const. But if you instead declare an arrow function with var and use it early, you will get a "type error", because it WAS hoisted, but not yet defined.
@CANIHAZURDREAMSPLS
@CANIHAZURDREAMSPLS Жыл бұрын
I finally know why we need to bind(this) for class components... because otherwise "this" is global context rather than parent context - thank you sir!
@MonsterlessonsAcademy
@MonsterlessonsAcademy Жыл бұрын
You are welcome!
@johnacsyen
@johnacsyen 9 ай бұрын
@11:45, the function version did not have return, which is why is logs to undefined. if return is added to line 9, it also returns 'Fluffy'
@pgn666
@pgn666 Жыл бұрын
THRE IS A MASSIVE BUG in 10:17 example. Line 7 misses "return" and only this is why line 16 logs 'undefined' to the console!!!
@MonsterlessonsAcademy
@MonsterlessonsAcademy Жыл бұрын
You are totally right
@anon1999-h5j
@anon1999-h5j 2 жыл бұрын
Your example for the context and this is wrong. The normal function returns undefined because you don't return anything from the function. The arrow function returns the pet name because you've written it in a way in which it returns this.name.
@cjmaaz
@cjmaaz 3 жыл бұрын
You explained Closures with one more js topic I was asked in an interview "Currying". I guess this is a bonus hidden tip for this video. 😛
@MonsterlessonsAcademy
@MonsterlessonsAcademy 3 жыл бұрын
Actually currying is the question that I like to ask people on interviews (because I'm a functional programming fan) but I didn't get this question often during interviews this is why I didn't include it in the list.
@cjmaaz
@cjmaaz 3 жыл бұрын
@@MonsterlessonsAcademy Then on that basis I'll get selected in that interview. 😆
@antoniozach91
@antoniozach91 3 жыл бұрын
Excellent video! That channel worth more boost! Keep going well man!
@MonsterlessonsAcademy
@MonsterlessonsAcademy 3 жыл бұрын
Thanks! Will do!
@miggu
@miggu Жыл бұрын
it's very hard to do a video like this, thank you. I think functions should be explained in hoisting as they can be invoked before declaring, I know it's one of those js quirks
@MonsterlessonsAcademy
@MonsterlessonsAcademy Жыл бұрын
Glad it was helpful!
@devilslide8463
@devilslide8463 3 жыл бұрын
Regarding class example and „this” binding. You are not returning anything from getSurname function. That is why I think you are getting undefined. If you console log “this” for both functions you should get class context.
@MonsterlessonsAcademy
@MonsterlessonsAcademy 3 жыл бұрын
Yes, you are correct, you passed the interview :) I forgot to write return there -_- P.S. this in function console.log will be undefined.
@devilslide8463
@devilslide8463 3 жыл бұрын
@@MonsterlessonsAcademy By logging “this” I meant something like this: codesandbox.io/s/nifty-chebyshev-8z1yo Both functions are reporting “this” as class object.
@MonsterlessonsAcademy
@MonsterlessonsAcademy 3 жыл бұрын
@@devilslide8463 wow actually I expected it to be undefined as in such construction someMethod() { function foo () { console.log(this) } foo() } Sorry that I didn't test it properly :(
@devilslide8463
@devilslide8463 3 жыл бұрын
@@MonsterlessonsAcademy exactly honestly speaking it was also my expectation:) If we throw out classes and jump to prototypes we will see that clear difference between regular and arrow functions :)
@debjyotibanerjee6382
@debjyotibanerjee6382 2 жыл бұрын
@@MonsterlessonsAcademy Its a dangerously beautiful tutorial...
@KAZVorpal
@KAZVorpal 5 ай бұрын
Hold on, that's not an example of closure, really. That's an example of currying. In fact, by showing it as an example of closure, you're going to confuse the viewers. Currying is a whole, separate, and relatively rare trick and question you will far less often encounter. Also, you'd rarely, if ever, evoke both halves at once like that(3)(2)...so it's a bad example even then. More likely, you'd do something like: const totaler = addTo(3); totaler(2); If you're going to instantly evoke both of them like addTo(3)(2), then you're just wasting your time and should have just written the function to take (3, 2).
@MonsterlessonsAcademy
@MonsterlessonsAcademy 5 ай бұрын
It's not an example of currying. On 5:00 your can see a variable inside closure.
@KAZVorpal
@KAZVorpal 5 ай бұрын
@@MonsterlessonsAcademy It CONTAINS closure, but is currying. You may as well claim it's not an example of closures because it contains a function. That there is one thing in it doesn't change that its MAIN demonstration is of a different thing. Embedding a function in another function and calling them in sequence is currying. That is the MAIN lesson here, which is going to be confusing to viewers.
@victortochila9642
@victortochila9642 2 жыл бұрын
You have an error explaining the difference between arrow and plain function: First of all, you used classes, which is really bad for explaining diff between arrow vs regular functions. If I add following code to jsfiddle/codesandbox I am getting compiler errors => we should use only methods inside classes. But anyway your getSurname method returns nothing, so undefined is the only value you could get. If you return this you would get object here, this is some weird behavior of classes which is not obvious again. And generally, after your example, it seems like we need to use arrowFunctions for object methods, when the reality is opposite: We need to use arrow functions almost everywhere where we want to save current context e.g. callbacks, but for object methods, where we need to use regular functions.
@MonsterlessonsAcademy
@MonsterlessonsAcademy 2 жыл бұрын
Hi thank you for your input!
@100PEACEOFLIFE
@100PEACEOFLIFE Жыл бұрын
thanks!
@MonsterlessonsAcademy
@MonsterlessonsAcademy Жыл бұрын
Welcome!
@sandtree
@sandtree 3 жыл бұрын
Thanks.
@MonsterlessonsAcademy
@MonsterlessonsAcademy 3 жыл бұрын
You're welcome
@tianadede349
@tianadede349 3 жыл бұрын
thanks
@MonsterlessonsAcademy
@MonsterlessonsAcademy 3 жыл бұрын
You're welcome!
@kumailn7662
@kumailn7662 2 жыл бұрын
you missed the return keyword in function
@MonsterlessonsAcademy
@MonsterlessonsAcademy 2 жыл бұрын
Yeap
@doniaelfouly4142
@doniaelfouly4142 Жыл бұрын
thanks
@MonsterlessonsAcademy
@MonsterlessonsAcademy Жыл бұрын
You're welcome!
@doniaelfouly4142
@doniaelfouly4142 6 ай бұрын
thanks
@MonsterlessonsAcademy
@MonsterlessonsAcademy 6 ай бұрын
Welcome
Must Know Javascript Features - Simplify Your Code
11:12
Monsterlessons Academy
Рет қаралды 2,3 М.
Javascript Interview Questions and Answers - Dominate Your Next Interview
1:02:33
Monsterlessons Academy
Рет қаралды 75 М.
Quando eu quero Sushi (sem desperdiçar) 🍣
00:26
Los Wagners
Рет қаралды 15 МЛН
Арыстанның айқасы, Тәуіржанның шайқасы!
25:51
QosLike / ҚосЛайк / Косылайық
Рет қаралды 700 М.
Javascript Coding Interview Questions- You Must Know Them
17:06
Monsterlessons Academy
Рет қаралды 19 М.
I loved solving this junior react interview challenge
26:02
Web Dev Cody
Рет қаралды 155 М.
JavaScript Interview Prep: Functions, Closures, Currying
1:29:03
freeCodeCamp.org
Рет қаралды 166 М.
React Interview Questions and Answers - Dominate Your Next Interview
45:43
Monsterlessons Academy
Рет қаралды 30 М.
Javascript interview | Closure
11:44
Hitesh Choudhary
Рет қаралды 38 М.
Typescript Interview Questions and Answers - Dominate Your Next Interview
53:34
Monsterlessons Academy
Рет қаралды 14 М.
5 Essential JavaScript Interview Questions
20:32
Coding With Chaim
Рет қаралды 93 М.