I am presenting as an exam to see my level of JS and I have several doubts. I took out 39/45 and my mistakes are as follows and I would like someone to clarify them a bit:
What will be displayed on the console when "this" calls the following method? (What is logged to the console as "this" when the following method was called?)
var myObj = { property : "that", whatsThis : function(that) { setTimeout(function () { console.log(this); }, 0); } } myObj.whatsThis("?");
My answer was that
in case I thought it would be myObj
but I do not understand much why is window
the correct answer, I give an example where it did go well:
What is "this" when the following method is called? (What is "this" when the following method was called?)
var myObj = { property : "that", whatsThis : function(that) { return this; } } myObj.whatsThis("?");
I put myObj
as an answer and it was correct and it was because when I return this
I refer to the object and I ignore the parameter that happened because I do not do anything but one question here: if I put return this.property
would print "? " true? since I'm changing the value to local property, right?
Well that's my doubt the other one is
Why should you use asynchronous processing in your JS code? (Why should you use asynchronous processing in your JavaScript code?)
Learn more about synchronous and asynchronous requests here: link
Note: There are 2 correct answers to this question.
To speed up requests on the server when they do not need authorization on the server - To speed up server requests as they do not need authorization checks on the server
To optimize the resource and task load in parallel - To optimize resource loading and parallelize tasks Correct!
To prevent the server from crashing with multiple requests - To avoid server crashes due to multiple requests Your Answer
To prevent the user interface from being responsive during task execution - To avoid your UI becoming unresponsive due to long-running tasks (Correct)
That is more theoretical and if it makes sense it is assumed that with asynchronous processing is to load other processes without freezing the screen, right? And if it freezes the screen is damaged and responsive? Or I did not understand much that last only there I was wrong.
Sorry in advance for the translation there are things that do not translate very well hehe