Thanks a lot for this. I enjoy this video very much. Normally you're so prepared in your videos and xplain things in elegant confidence. now I get to see your hard thinking mimics (which was a pleasant :D) and then managed the top 5%. Despite all u seem so humble.
when you add an element into an array with an index greater than the length of the array, it adds empty elements before this. So when you execute a[100]=1, the array's length becomes 101
Correct - it fills in all the elements in-between with "undefined" and will return 101 because of 0-indexing. This is definitely one of the ones WDE got wrong, lol
@@Malvitima0 There's a very good reason for that. Imagine if the length in the example actually was 4. If you tried to loop over an array, `for (let i=0; i
@Malvitima0 Arrays on not-so-high level languages (like C) are continuous strips of memory, which has an implicit order (from lowest memory address number to highest memory address number). Higher level languages (like JS) are not obliged but they do use similar concepts for their lists/arrays, which is a group of objects in an ordered, indexed manner. If you think about it, if you wanted the result to be 4, you would much rather be expected to use maps. So, if you assign the 100th element of the "memory strip", it is logical that this "strip" must also contains the 99th, 98th, 97th ... elements. Hope it helps!
The array length is 101, it always picks the highest one and returns undefined for the uninitialized indices: > let a = [1, 2, 3] undefined > a[100]=100 100 > a.length 101 > a[88] undefined
Awesome video! The answer to the first one is "immediately". There was no HTTP request in the code. I think you may have overthought that one and took into account the way that the JavaScript is actually loaded into the interpreter via the browser.
@@josephcagle if that code would be in the head and executed in the head, that querySelector call would return null or an error, not sure since I learned my lesson not to query the DOM before it is loaded.
q1 - Immediately q4 is 101. Arrays are linear data structures. Which means data is arranged sequentially. So if there is an item at position 100, then index 0-99 must exist q12 - 1
Q:12's correct answer is 1. It is about closures. When a variable of a function does not exist, it will look for it at its outer lexical environment. In other words, variables wont be looked at the outer place where the function was invoked, but where it was declared. Using 'var' or 'let' will have no difference here, the result will be the same.
that's correct but for the sake of completeness, if the second keyword var was omitted, v's value would have been updated and the result would be 2. using var creates an internally scope variable v in function f2. var or let would have made no difference.
@@Shivey73 i dont think it will. var is function scoped in f2 so it will stay there. f1 doesn't have var v so it will look outside ( in this case the global scope). so the answer is 1
@@らんちょ-e5d maybe my explanation was not clear enough. If in f2 you state v=2 instead of var v=2, the global var which was 1 would be updated to 2 and the answer would become 2.
Hi Kyle, I love your videos, and you're definitely smarter than me!. I rarely comment but feel a correction is in order as it's fundamental: Q12 (on var and v=1, v=2). The var inside f2 is not the same as the global var! (it would be only if var was absent). Scope is defined by the block so declaring (with var, or let for that matter) v inside function f2, makes it invisible outside of that function. The declaration inside f2 does not alter the global value of V. The reference to V in f1 can only see the globally-declared V and so the answer is 1 not 2. (I probably haven't explained it as well as you could but the results never lie, try it!). Thanks for your efforts and keep them up!
I took this test back in the spring and didn't get in the percentile needed to pass. I have used javascript on and off for years, but kind of just learned what I needed to know in order to complete whatever task I was working on. Last month I saw Kyle's javascript simplified course and decided to give it a shot. I took the linked in quiz again after completing the course and got top a 5% score. This is not any kind of paid endorsement :) but it is definitely a recommendation to consider the course if you need to strengthen your javascript skills.
That is awesome Jim! I am so glad that the course was able to teach you everything you needed to know in order to ace this quiz. I also hope it taught you what you need in order to build any project you can think of.
In question 12 it will log 1. Since during compilation, the value if v inside f1 will reference the variable in either its outer or local lexical scopes. v2 has been declared inside a different lexical scope, thus it doesn't re-declare var in the global scope. In other words, the v variable declared in the outer scope becomes a closure of f1 anonymous function, and is going to carry this "backpack" wherever it gets called.
Number 1 would run the code outside of setTimeout first even if you set 0ms as the argument, because it places the code inside the setTimeout function at the bottom of the execution stack. I liked this video, it shows that even people who know a lot don't know everything.
10:25 It would have redefined global var if we didn't use var keyword with it As var is scoped to function not global, f1 will log the global var v with value 1
It's great how relaxed you are in your videos. Also, amazing that you get straight to the point without talking about nonsense for minutes. Keep up the good work!
Q12) var v = 1; var f1 = function() { console.log(v); }; var f2 = function() { var v = 2; f1(); }; f2(); When the code is executed, the following happens: The variable v is declared in the global scope and assigned the value 1. The function f1 is defined, which logs the value of v to the console. Since v is not defined locally within f1, it references the global variable v. The function f2 is defined, which declares a new local variable v and assigns it the value 2. This local variable v shadows the global variable v within the scope of f2. Inside f2, the function f1 is invoked. When f1 is executed, it tries to log the value of v. Since v is not defined locally within f1, it looks for the variable in the outer scope, which is the global scope. Therefore, it accesses the value of the global variable v, which is 1. Therefore, the code will print 1 to the console. NOT 2.
You're an amazing teacher Kyle! Your videos are concise, straightforward, and fairly easy to understand even for a beginner like me. I'm only 14, but I'm trying to make the most of my quarantine so that's why I started coding since last year. Watching your videos helps me a lot when I get stuck on a project!
keep doing. If you learn JS at 14, the time you will be 16 or 18, I am sure you would have built you own startup. Here, 36, that still is reasoning about those question. Of course I got other software language
void is for a function that returns no value. If you use return, it does not return a value - no errors, just no value is returned. It is basically a precautionary thing or a thing that you'd do for stuff that returns a value that you don't want returned.
@@mantinez1 YOU GET 5% and YOU GET 5%! lol It is based off of the number of people that have already taken the quiz. Honestly, it is a cool thing to do over coffee though.
Kyle, thank you for this video. And in 13th question there are two correct answers: discountPrice = function(price){...} without 'var' will also create function just fine. Looks like a mistake in this quiz.
This is true, and also true for assigning any variable without a variable keyword, but it will assign it to the global object and can overwrite global properties, like Window properties if the naming isn’t careful or secure. You can, however, do the same thing inside curly braces and protect the global scope. So, for example { discount = function(price) { return price * 0.85; }}. But obviously you would also have to use the function within the same block scope too, then. Though strangely when I try this in devtools console, I can still call the function after closing the braces and hitting enter, and it’s also not on the window object, unlike if you were to do it without the outside braces…
I failed the JS test even though I use it daily and passed the C# and I hardly know C# and almost never use it. IMO those are some tricky questions that you will almost never run into and if you do you can google your way to the right solution to get the job done. Also, it is best not to try so hard to remember everything and develop a mind that can figure out how to solve problems instead of remembering everything someone else taught you.
4. Answer is 101 12. Answer is 1 because v === 2 only inside f2 it would have overwrite the "ouside" v without the var keyword 13. I agree with you, but answer number 2 could work as well (it is not a good practice to add variable to the gloabal object but this is not a crime either) 14. I'm not sure what the problem is expect the result is very predictable
I think the answer to the first question should be immediately. Timeout functions and other promise calls and what not will not be executed till the global thread of execution is done. Then only javascript will look for stuff in the micro task queue and callback queue. In this case setTimeout will always run last. Even if you have 1000 console.logs after that. Watch Javascript hardparts by will sentance. (Frontend masters)
Hey man, I just wanted to thank you for making all of these awesome videos. I (computer science grad) started watching your css/html videos and have been following all your projects ever since. Keep up the great work!
Great stuff, I really enjoy and appreciate your content. Regarding Question 12 about what value will function f1 will log to console. I know reason of that but I got it wrong anyway as I rushed through when I tried to solve it along with you when I was watching video. The trick here is that var is function scoped, however it is also as important that scope of function is declared based on where function is declared, not where it is executed and here we have both function declared in global scope. For example if we have: var i = 1; function f1() { f2(); var i = 2; function f2() { console.log(i) } } f1(); then we would get three scopes: - global scope ( var i =1, function f1) - function f1 scope (var i =2, function f2) - function f2 scope () Now when execution of f2 happen, it check if there is variable declaration for i , if not it would look up in closest/nearest outerscope that is f1 scope. Here js parser would find variable declaration for i with value of 2 assigned so it would use that value in scope of function 2. I believe it is similiar but not exactly same as closure concept, that would worked differently, but correct me if I am wrong
5% here too! But I answered some questions differently haha It'd be great if we could know which questions we got wrong :/ Thanks for the great content as usual :) You are an inspiration
In question 12 the answer is 1 because of the second assignment of v is actually a new initial variable of the function 'f2', which means that it doesn't change the global 'v' variable..
Question 13, at least in the console you don't have to use let/const/var to create a function, but it will be a property of the window object. This doesn't work in ES6 modules though.
howdy. great work. the function would have logged 1. f1 closed over v global v, not the f2 local v. since f1 does not accept v as an input, f1 logs unchanged global v 1. var is still function scoped. let and const are block scoped, in addition, so they will need to be redeclared in loops, if statements, etc. if f2 said v = 2, f1 would log 2. this is an example of why shadowing can get confusing. you lose track of what scope the variable is in.
I was thinking Q12 @ 10:00 would print 1. f1 prints the global variable v, f2 defines a new variable v, which is function scope, and this is different from the v logged in the f1 function.
I was delighted when you got the a[100] question wrong, not in a malicious way mind you, but because it makes you seem more human, lol. I was shouting the entire time "it just fills the in-between values with 'undefined'!", lol
In my opinion In number 12 since you are using var you are creating a new local variable inside the scope of the function f2 and you are not assining the number 2 to the v present in the global scope (window)... if the keyword var wasn't there it would have been 2... hope to help someone with that... by the way thanks for sharing :D
Question number 12 will return you a value of 1 because f1 forms a closure with the global variables v=1 so when you invoke f1 inside f2 it doesn't really care about the local v=2 unless you pass it as an argument.
Question 12 the correct answer is 1 because the f1 function looks for the first global variable v outside it's scope, which is var v = 1. Var v in the second function becomes a new variable trapped within the scope of the second function.
I've tried some of these linked in tests. They seem to focus on very specific and not often used details / behaviours of the language. In my opinion, knowing those is not what makes you a skilled developer. But that's my opinion.
At Q4 is 101 not 4. It actually sets the array length to 101 and keeps any unset value to undefined and with a for...of it goes through all 101 elements, but with forEach or for...in uses only those 4 values (even if they are set to undefined later on). Actually I don't believe those values will be undefined but some other weird empty value (like the value is deleted) and you have to use a.hasOwnProperty(index) to check if there is anything. var a = [, 2]; a.hasOwnProperty(0) == false; a.hasOwnProperty(1) == true; a.length == 2; At Q13 the second option doesn't create a new function on the global scope (window) and then can be accessed via window.discountPrice? Anyway your choice is correct
var v = 1 var f1 = function(){ console.log(v) } var f2 = function() { var v = 2 f1() }; f2() it prints 1 because of scope, in funct 2 your declaring a new varaible inside its scope not reasigning and f1 doesnt know of a declared variables inside f2. like if you did v = 2 instead of using var then your taking the variable it has access to and modifying it
oh gosh I got top 3% and I still don't know how to make a simple todo list xd -edit : I'm actually not kidding, I did get 3% but I'm still not able to make apps without following tutorials :/...
Most apps are crud apps. Just write down some key points and practice doing it blind without a tutorial. Getting stuck is a part of the process. I believe you can do it!
void is for IIFEs. I'm no expert, but basically it just means you don't want anything returned. There is another way to do it I believe if you wrap it in () so you don't have to use the keyword.
That was fun! very basic, I wish JavaScriptSkillzQuiz could be a hashtag online.😊 I learned something new from question 8; get methods must have went over my head in the spaghettis curriculum of TS/JS but sure looks very sugary! Makes the class paradigm worth using more honestly.
I have already cleared linkedin javascript assesment test because i have been coding javascript since last 20 years, but i am not smarter most youtubes devs to showcase what I know so far.
So I think you got 3 wrong....Question 1 - I think you overthinking a little much and the answer is immediately. Question 4 is definitely 101. Question 12 is 1 because closures.
@@patterntrader690 when f1 is called inside f2, since f1 is declared in the global scope it logs v which is in that scope itself so it will consider it as 1
Sorry to say but i caught you wrong in question 5 and 12 Answer to 5 is 101.... I don't know the exact explanation but when we do a[100]='shs' the it just go from 3 to 99 and assign them with default value. And thus the length now is 101 Answer to 12 is 1 because whenever or wherever f1 is called it takes the value of v from its lexical environment as it already had formed a closure with its lexical environment. So anytime f1 is called it always refer to var v=1 no matters if you are defining var v=2 just above it.
On question 12 you made a mistake for sure. Because the second-time v variable is declared inside of the function as var v =2 which means it is different variable, it is not referencing the previous v variable to reassign the value of the previous v variable you have to reference it like v = 2; without var keyword.
That’s right. When the console.log looks for ‘v’ within f1 and doesn’t find anything, it looks one level outside the execution context, not one level down the scope chain. One level outside of the f1 context is the global context where v = 1.
I don't like test like that. because it's not presented skill u have (especially for working) sure the test will reflect about your knowledge and fundamental. but still in the end of work, i use google and stackoverflow a lot. the needed skill is - 'solving the problem', how to convert solution into algorithm then convert into code. - troubleshot when result error / unexpected. why? find which part is wrong, is algorithm? or code? of-course knowladge and fundamentel need atlast to make your code not become spaghetti. imo test like those (in linkedin) not filtering right candidate. for u guys, better make lot project for portfolio.
Hey! You had the same tricky question as me on my last interview last week. var a=1; function foo() { console.log(a) } function foo2() { var a=2; foo(); } foo2(); I answered 2 and followed the same logic like you but the answer is 1. This is because function foo is using a global variable a. If they as you just to console.log a inside foo2, it will print 1, but in this case you're executing foo.
I was thinking about 1 on Q12 the one with var v=1 , I 've just run the code and is apparently 1 lol I've nailed one :)) luckily seen a tutorial today that was just explaining let/var behave in a function. Explanation is that the 'console.log' is the F1 function and the nearest declaration is in the global scope which is 1.
WDS could you please put a new video on ES2017 and what feature love about that. Why I'm asking this is around 94% of websites and engines are compatible with ES2017 standard and very few people fairly explained about. As you're my best JS teacher I love to hear your talks about ES2017 feature.
The first 1000 people to use the link will get a free trial of Skillshare Premium Membership: skl.sh/webdevsimplified12201
Oakey
Now way I am smarter than you. You are a walking wikipedia
One less available! Thanks a lot buddy, the javascript section is insane!! Defintly an happy christmas studying 🤣🤣😍🤑
Thanks a lot for this. I enjoy this video very much. Normally you're so prepared in your videos and xplain things in elegant confidence. now I get to see your hard thinking mimics (which was a pleasant :D) and then managed the top 5%. Despite all u seem so humble.
when you add an element into an array with an index greater than the length of the array, it adds empty elements before this. So when you execute a[100]=1, the array's length becomes 101
That's so fuck-up
@@Malvitima0 I so agree
Correct - it fills in all the elements in-between with "undefined" and will return 101 because of 0-indexing. This is definitely one of the ones WDE got wrong, lol
@@Malvitima0 There's a very good reason for that. Imagine if the length in the example actually was 4. If you tried to loop over an array, `for (let i=0; i
@Malvitima0 Arrays on not-so-high level languages (like C) are continuous strips of memory, which has an implicit order (from lowest memory address number to highest memory address number). Higher level languages (like JS) are not obliged but they do use similar concepts for their lists/arrays, which is a group of objects in an ordered, indexed manner. If you think about it, if you wanted the result to be 4, you would much rather be expected to use maps. So, if you assign the 100th element of the "memory strip", it is logical that this "strip" must also contains the 99th, 98th, 97th ... elements. Hope it helps!
The array length is 101, it always picks the highest one and returns undefined for the uninitialized indices:
> let a = [1, 2, 3]
undefined
> a[100]=100
100
> a.length
101
> a[88]
undefined
That's is CRAZY!!!
This is a perfect test to TEST how fast you can Google!
true😂
I run code and see what is answer ( fewquestion )
@@javascript2409 that's exactly what you're not supposed to do...
@@njpromethium atleast he will learn something this way because this stupid test wont show you where youve made a mistake
@@javascript2409 That's a nice idea. Never thought about it though.
Awesome video! The answer to the first one is "immediately". There was no HTTP request in the code. I think you may have overthought that one and took into account the way that the JavaScript is actually loaded into the interpreter via the browser.
I really did. That one really tripped me up. Luckily the rest of the test was much more straightforward.
I think they were hoping to trip up people who might think that the querySelector() sends an HTTP request. Kinda weird and ambiguous IMO, though
@@josephcagle if that code would be in the head and executed in the head, that querySelector call would return null or an error, not sure since I learned my lesson not to query the DOM before it is loaded.
q1 - Immediately
q4 is 101. Arrays are linear data structures. Which means data is arranged sequentially. So if there is an item at position 100, then index 0-99 must exist
q12 - 1
Q:12's correct answer is 1. It is about closures. When a variable of a function does not exist, it will look for it at its outer lexical environment. In other words, variables wont be looked at the outer place where the function was invoked, but where it was declared. Using 'var' or 'let' will have no difference here, the result will be the same.
that's correct but for the sake of completeness, if the second keyword var was omitted, v's value would have been updated and the result would be 2. using var creates an internally scope variable v in function f2. var or let would have made no difference.
@@Shivey73 i dont think it will. var is function scoped in f2 so it will stay there. f1 doesn't have var v so it will look outside ( in this case the global scope). so the answer is 1
@@らんちょ-e5d maybe my explanation was not clear enough. If in f2 you state v=2 instead of var v=2, the global var which was 1 would be updated to 2 and the answer would become 2.
For those who come later and still don't understand: just compile it. You'll see what they say is true. Don't be like me, who had to question this.
Hi Kyle, I love your videos, and you're definitely smarter than me!. I rarely comment but feel a correction is in order as it's fundamental:
Q12 (on var and v=1, v=2). The var inside f2 is not the same as the global var! (it would be only if var was absent). Scope is defined by the block so declaring (with var, or let for that matter) v inside function f2, makes it invisible outside of that function. The declaration inside f2 does not alter the global value of V. The reference to V in f1 can only see the globally-declared V and so the answer is 1 not 2. (I probably haven't explained it as well as you could but the results never lie, try it!).
Thanks for your efforts and keep them up!
I took this test back in the spring and didn't get in the percentile needed to pass. I have used javascript on and off for years, but kind of just learned what I needed to know in order to complete whatever task I was working on. Last month I saw Kyle's javascript simplified course and decided to give it a shot. I took the linked in quiz again after completing the course and got top a 5% score. This is not any kind of paid endorsement :) but it is definitely a recommendation to consider the course if you need to strengthen your javascript skills.
That is awesome Jim! I am so glad that the course was able to teach you everything you needed to know in order to ace this quiz. I also hope it taught you what you need in order to build any project you can think of.
In question 12 it will log 1. Since during compilation, the value if v inside f1 will reference the variable in either its outer or local lexical scopes. v2 has been declared inside a different lexical scope, thus it doesn't re-declare var in the global scope. In other words, the v variable declared in the outer scope becomes a closure of f1 anonymous function, and is going to carry this "backpack" wherever it gets called.
Number 1 would run the code outside of setTimeout first even if you set 0ms as the argument, because it places the code inside the setTimeout function at the bottom of the execution stack. I liked this video, it shows that even people who know a lot don't know everything.
10:25 It would have redefined global var if we didn't use var keyword with it
As var is scoped to function not global, f1 will log the global var v with value 1
That s also what I was thinking
@@NachoDLF Yes it would be the same result.
This one actually a little bit tricky, we knew that var's scope could be confusing but in this case it's definitely 1 because the global var
Exactly. Var can be hoisted but not outside of block scope.
@@lurkinginthedark6498 "var" is function scoped
It's great how relaxed you are in your videos. Also, amazing that you get straight to the point without talking about nonsense for minutes. Keep up the good work!
Q12)
var v = 1;
var f1 = function() {
console.log(v);
};
var f2 = function() {
var v = 2;
f1();
};
f2();
When the code is executed, the following happens:
The variable v is declared in the global scope and assigned the value 1.
The function f1 is defined, which logs the value of v to the console. Since v is not defined locally within f1, it references the global variable v.
The function f2 is defined, which declares a new local variable v and assigns it the value 2. This local variable v shadows the global variable v within the scope of f2.
Inside f2, the function f1 is invoked.
When f1 is executed, it tries to log the value of v. Since v is not defined locally within f1, it looks for the variable in the outer scope, which is the global scope. Therefore, it accesses the value of the global variable v, which is 1.
Therefore, the code will print 1 to the console. NOT 2.
You're an amazing teacher Kyle! Your videos are concise, straightforward, and fairly easy to understand even for a beginner like me. I'm only 14, but I'm trying to make the most of my quarantine so that's why I started coding since last year. Watching your videos helps me a lot when I get stuck on a project!
keep doing. If you learn JS at 14, the time you will be 16 or 18, I am sure you would have built you own startup. Here, 36, that still is reasoning about those question. Of course I got other software language
Q1. it will show immediately since it is loaded directly on call stack. the setTimeout is a macrotask so it will execute after call stack is free
void is for a function that returns no value. If you use return, it does not return a value - no errors, just no value is returned. It is basically a precautionary thing or a thing that you'd do for stuff that returns a value that you don't want returned.
I gave this test yesterday and got 5% but never thought you will give this test. Happy to see you there :)
Love this! I did that quiz and got a top 5% of all the people that took this test! Very excited and curious to see what you get Kyle!
Congratulations
also got 5%, are we gettin lied or what?
@@paujoan401 mine says top 5% too haha, it's pretty sus, plus the total is like 750k people
@@paujoan401 I got top 5% also. I was actually shocked as I was unsure about many of my answers.
@@mantinez1 YOU GET 5% and YOU GET 5%! lol It is based off of the number of people that have already taken the quiz. Honestly, it is a cool thing to do over coffee though.
The most intense video I watched on RUclips. Congratulations Kyle!
Kyle, thank you for this video.
And in 13th question there are two correct answers: discountPrice = function(price){...} without 'var' will also create function just fine. Looks like a mistake in this quiz.
This is true, and also true for assigning any variable without a variable keyword, but it will assign it to the global object and can overwrite global properties, like Window properties if the naming isn’t careful or secure. You can, however, do the same thing inside curly braces and protect the global scope. So, for example { discount = function(price) { return price * 0.85; }}. But obviously you would also have to use the function within the same block scope too, then. Though strangely when I try this in devtools console, I can still call the function after closing the braces and hitting enter, and it’s also not on the window object, unlike if you were to do it without the outside braces…
First question is ‘immediately’ - the callback queue won’t run until the stack is empty.
👌
The array length was 101
actually that made me feel better that even Kyle can make mistakes lol
Was about to point that out XD
Glad to know I wasn't the only one thinking this.
I was thinking the same, for the array length to be 4 the element at index 100 should be just after the third element, not possible.
sparse arrays**
I failed the JS test even though I use it daily and passed the C# and I hardly know C# and almost never use it. IMO those are some tricky questions that you will almost never run into and if you do you can google your way to the right solution to get the job done. Also, it is best not to try so hard to remember everything and develop a mind that can figure out how to solve problems instead of remembering everything someone else taught you.
Man! you're the best CSS dev & the smartest one.
4. Answer is 101
12. Answer is 1 because v === 2 only inside f2 it would have overwrite the "ouside" v without the var keyword
13. I agree with you, but answer number 2 could work as well (it is not a good practice to add variable to the gloabal object but this is not a crime either)
14. I'm not sure what the problem is expect the result is very predictable
Happy to see I'm not the only one that was a bit stumped by the LinkedIn quiz. Much prefer real coding assessments like CodeSignal etc.
I think the answer to the first question should be immediately. Timeout functions and other promise calls and what not will not be executed till the global thread of execution is done. Then only javascript will look for stuff in the micro task queue and callback queue. In this case setTimeout will always run last. Even if you have 1000 console.logs after that.
Watch Javascript hardparts by will sentance. (Frontend masters)
Hey man, I just wanted to thank you for making all of these awesome videos. I (computer science grad) started watching your css/html videos and have been following all your projects ever since. Keep up the great work!
Great stuff, I really enjoy and appreciate your content. Regarding Question 12 about what value will function f1 will log to console. I know reason of that but I got it wrong anyway as I rushed through when I tried to solve it along with you when I was watching video.
The trick here is that var is function scoped, however it is also as important that scope of function is declared based on where function is declared, not where it is executed and here we have both function declared in global scope. For example if we have:
var i = 1;
function f1() {
f2();
var i = 2;
function f2() {
console.log(i)
}
}
f1();
then we would get three scopes:
- global scope ( var i =1, function f1)
- function f1 scope (var i =2, function f2)
- function f2 scope ()
Now when execution of f2 happen, it check if there is variable declaration for i , if not it would look up in closest/nearest outerscope that is f1 scope. Here js parser would find variable declaration for i with value of 2 assigned so it would use that value in scope of function 2. I believe it is similiar but not exactly same as closure concept, that would worked differently, but correct me if I am wrong
I took this test about a month ago and got top15%. You're good 😅
5% here too!
But I answered some questions differently haha
It'd be great if we could know which questions we got wrong :/
Thanks for the great content as usual :)
You are an inspiration
I got all of them right except 11. That was the first time I've heard of void in js.
In question 12 the answer is 1 because of the second assignment of v is actually a new initial variable of the function 'f2', which means that it doesn't change the global 'v' variable..
Question 13, at least in the console you don't have to use let/const/var to create a function, but it will be a property of the window object. This doesn't work in ES6 modules though.
howdy. great work. the function would have logged 1.
f1 closed over v global v, not the f2 local v. since f1 does not accept v as an input, f1 logs unchanged global v 1.
var is still function scoped. let and const are block scoped, in addition, so they will need to be redeclared in loops, if statements, etc.
if f2 said v = 2, f1 would log 2.
this is an example of why shadowing can get confusing. you lose track of what scope the variable is in.
+1 for mentioning "shadowing" you must be old skool JS ✌
I was thinking Q12 @ 10:00 would print 1.
f1 prints the global variable v,
f2 defines a new variable v, which is function scope, and this is different from the v logged in the f1 function.
3:54 1 is PHP, 2 is Haskell, 3 is Javascript
first isn't php
Actually really enjoyed this video, do another 👌
I was delighted when you got the a[100] question wrong, not in a malicious way mind you, but because it makes you seem more human, lol. I was shouting the entire time "it just fills the in-between values with 'undefined'!", lol
In my opinion In number 12 since you are using var you are creating a new local variable inside the scope of the function f2 and you are not assining the number 2 to the v present in the global scope (window)... if the keyword var wasn't there it would have been 2... hope to help someone with that... by the way thanks for sharing :D
Question number 12 will return you a value of 1 because f1 forms a closure with the global variables v=1 so when you invoke f1 inside f2 it doesn't really care about the local v=2 unless you pass it as an argument.
Question 12 the correct answer is 1 because the f1 function looks for the first global variable v outside it's scope, which is var v = 1. Var v in the second function becomes a new variable trapped within the scope of the second function.
If the var in the f2 function was not used then and just v =2 was used it would have reassigned the global variable to 2.
Learned a lot. Please do take these type of assessments for Front-End as these will help newer devs like us to evolve. Cheers!
I've tried some of these linked in tests. They seem to focus on very specific and not often used details / behaviours of the language. In my opinion, knowing those is not what makes you a skilled developer. But that's my opinion.
I took this test last month and got top 5%. Damn! I am good!!😎
thanks men I really enjoyed this quiz with you hope you do it again and again !! I like it bro
thanks for this kyle you are great
At Q4 is 101 not 4. It actually sets the array length to 101 and keeps any unset value to undefined and with a for...of it goes through all 101 elements, but with forEach or for...in uses only those 4 values (even if they are set to undefined later on). Actually I don't believe those values will be undefined but some other weird empty value (like the value is deleted) and you have to use a.hasOwnProperty(index) to check if there is anything.
var a = [, 2];
a.hasOwnProperty(0) == false;
a.hasOwnProperty(1) == true;
a.length == 2;
At Q13 the second option doesn't create a new function on the global scope (window) and then can be accessed via window.discountPrice? Anyway your choice is correct
var v = 1
var f1 = function(){
console.log(v)
}
var f2 = function() {
var v = 2
f1()
};
f2()
it prints 1 because of scope, in funct 2 your declaring a new varaible inside its scope not reasigning and f1 doesnt know of a declared variables inside f2. like if you did v = 2 instead of using var then your taking the variable it has access to and modifying it
Please do more videos like this
oh gosh I got top 3% and I still don't know how to make a simple todo list xd
-edit : I'm actually not kidding, I did get 3% but I'm still not able to make apps without following tutorials :/...
cause it's a totally useless app. Do something which makes sense to yourself.
ha ha you crack me up lol
Most apps are crud apps. Just write down some key points and practice doing it blind without a tutorial. Getting stuck is a part of the process. I believe you can do it!
Rust POGU
@@kervensjasmin1508 I thought I was just being overly reductive when I had that thought but it turns out I wasn't the only one lol.
More videos like this one please!
Keep these coming Kyle
dude the correct way is ( ) => ({ }) or ( ) => { return { }; } but you're on the top 5% congrats
Holy shit I was exactly waiting for this one!!
Im a beginner and this was helpful to me. I struggle with knowing how much I actually know. I got most right as well.
void is for IIFEs. I'm no expert, but basically it just means you don't want anything returned. There is another way to do it I believe if you wrap it in () so you don't have to use the keyword.
I didn't skip your video, Very interesting video
Wow what an awesome helpful video! Thanks for posting. The suspense had me biting my nails lol
the total length is 101. But if the property(or key) of the array is a string, it doesn't affect its length.
This was very informative thanks glad to hear your thoughts on the test
That was fun! very basic, I wish JavaScriptSkillzQuiz could be a hashtag online.😊
I learned something new from question 8; get methods must have went over my head
in the spaghettis curriculum of TS/JS but sure looks very sugary! Makes the class paradigm worth using
more honestly.
I have already cleared linkedin javascript assesment test because i have been coding javascript since last 20 years, but i am not smarter most youtubes devs to showcase what I know so far.
So I think you got 3 wrong....Question 1 - I think you overthinking a little much and the answer is immediately. Question 4 is definitely 101. Question 12 is 1 because closures.
What’s wrong on 3?
@@patterntrader690 when f1 is called inside f2, since f1 is declared in the global scope it logs v which is in that scope itself so it will consider it as 1
@@brijspy can you please give some links to read about this, not closures but this specific subject, I'm very confused.
var is function-scoped so the declaration in f2 doesn't even come into play
It's simple buddy var v is functional scoped in f2() so it is not related to global var v
There is no need of closures in here.
I was top 15% in about 2M people that have presently taken the test , pretty impressive after learning java-
script for some weeks
The the test isn't impossible if you study xD
10:28 "var" is function scoped!!!
that array length better to throw a index error ,and I guess the value V would be 1 because it’s rededined in f2, not a assignment.
var a = [1,2,3];
a[100] = 100
console.log(a.length); => gives 101
here rest of element is undefinded
thank you man after I watch this video and took the same test and successes with the top 15% . ohhhh yea
Sorry to say but i caught you wrong in question 5 and 12
Answer to 5 is 101.... I don't know the exact explanation but when we do a[100]='shs' the it just go from 3 to 99 and assign them with default value. And thus the length now is 101
Answer to 12 is 1 because whenever or wherever f1 is called it takes the value of v from its lexical environment as it already had formed a closure with its lexical environment.
So anytime f1 is called it always refer to var v=1 no matters if you are defining var v=2 just above it.
Q4 is actually 101. i tested in the console. every spot from 3 - 100 is just undefined.
Awesome, interesting ❤️ , waiting for next upload as this.
we need more, i mean a lot
I have to learn a lot... I was in top 15% of 824k
Your video pointed out my mistakes...
Thanks. I really like your videos, I learned a lot from you.
This guy has THE VOICE!
10:58 it does in global scop if can't find it
number 4 question answer (101)
On question 12 you made a mistake for sure. Because the second-time v variable is declared inside of the function as var v =2 which means it is different variable, it is not referencing the previous v variable to reassign the value of the previous v variable you have to reference it like v = 2; without var keyword.
I already have that batch on js,css, and python
for question 12 I got 1.
That’s right. When the console.log looks for ‘v’ within f1 and doesn’t find anything, it looks one level outside the execution context, not one level down the scope chain. One level outside of the f1 context is the global context where v = 1.
Thanks Kyle for giving some wrong answers on purpose just to make us feel better
I wish I did it on purpose. There were a few questions I seriously didn't know
var supports functional scope, but not the block scope. For question 12 the answer was 1.
I became top 3% in JavaScript exam in LinkedIn
I don't like test like that. because it's not presented skill u have (especially for working)
sure the test will reflect about your knowledge and fundamental. but still
in the end of work, i use google and stackoverflow a lot.
the needed skill is
- 'solving the problem', how to convert solution into algorithm then convert into code.
- troubleshot when result error / unexpected. why? find which part is wrong, is algorithm? or code?
of-course knowladge and fundamentel need atlast to make your code not become spaghetti.
imo test like those (in linkedin) not filtering right candidate.
for u guys, better make lot project for portfolio.
Hey! You had the same tricky question as me on my last interview last week.
var a=1;
function foo() {
console.log(a)
}
function foo2() {
var a=2;
foo();
}
foo2();
I answered 2 and followed the same logic like you but the answer is 1.
This is because function foo is using a global variable a. If they as you just to console.log a inside foo2, it will print 1, but in this case you're executing foo.
Yeh. I never use var so my logic was faulty in that one :(
Yes you right. if the function foo() was declare with a param like foo(a) then it would return 2
var a = ['dog', 'cat', 'hen'];
a[100] = 'fox';
console.log(a.length);
the answer is 101
void is the return type of a function if it does not return anyting isn't it?
Var is function scoped my dude. You were printing the global v which was 1.
I'm pretty happy as I managed a 12/15.
great video !
I was thinking about 1 on Q12 the one with var v=1 , I 've just run the code and is apparently 1 lol I've nailed one :)) luckily seen a tutorial today that was just explaining let/var behave in a function. Explanation is that the 'console.log' is the F1 function and the nearest declaration is in the global scope which is 1.
in question 12 in will print 1 because f1 functoin will get called
because var v redefined after f1 and not passed to f1.
do them all dude. fun fun fun. gonna do em too.
var is function scoped so "var v = 2" does not redefine the global v because you are declaring it inside a function
that was best ever, thanks
You should try taking the React test - it's bloody confusing!
That will be one of the next ones I do!
Want more of such videos for HTML, CSS
I am looking forward to doing the css one
make them
Please do it for React as well
WDS could you please put a new video on ES2017 and what feature love about that. Why I'm asking this is around 94% of websites and engines are compatible with ES2017 standard and very few people fairly explained about. As you're my best JS teacher I love to hear your talks about ES2017 feature.