-
Notifications
You must be signed in to change notification settings - Fork 9
Frontendquestions #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 5 commits
8a7f57d
7c01767
b01ae36
1c4b173
92157e5
550c68c
ef354b0
7bb920f
a4bf78d
3002d9d
0cbeccf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
1. [ Native Javascript Questions ](/Web-Development/NativeJavascript/questions.md) | ||
2. [ Native Javascript Answers ](/Web-Development/NativeJavascript/answers.md) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Answers to the frontend questions Native script | ||
1. | ||
``` | ||
function sum(){ | ||
let | ||
sumOfArgs=0, | ||
i=0; | ||
for(;i<arguments.length;i++){ | ||
sumOfArgs+=arguments[i]; | ||
} | ||
return sumOfArgs | ||
} | ||
``` | ||
2. Inheritance works differently in javascript not like in other languages, here we have parent object set in the prototype properties of the object which it refers if it does not find the current object. It will be a chain of references to parent objects in case of multiple inheritances so it is called prototype chain. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is kind of gibberish. |
||
3. Closures in javascript are the block of code and the variables used in it are bound to the block through the variables are defined in its parent object. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand the intent but this is very poor way to write. |
||
4. `var` variables are hoisted prior to the variables are executed but `const` and `let` or not. And simple properties defined by `const` cannot be changed. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All variables (var, const, let) are hoisted. Read here Doesn't explain the difference between |
||
5. b will be `undefined` as only the variables are hoisted but not the assignment. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the code, the function a is never called, so your answering the wrong question. |
||
6. We know javascript is single threaded but the browser is not. The browser will have javascript engine thread and network thread, so when a network request is completed from network thread which is running parallelly to javascript engine thread and the javascript engine will execute the network request callback once it finishes its request. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wrong answer. You probably should be talking about event loop and tasks, microtasks in the event loop. Watch this |
||
7. Promises make syntax easier and are the best way to handle asynchronous functions. We can do that with callback but when there is a chain of asynchronous functions it is difficult to handle there. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This does not tell what's really the difference between them. Also, Promises being the best way to handle async stuff is very subjective. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Promises do not add any syntax. That's why you can polyfill them in browser with ES5 only support. Callback return values have to be consumed eagerly whereas promisified values can be consumed lazily. You can write more differences. |
||
8. React more developer friendly and Angular build on solid software principles like MVC and dependency injection. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The question says Which one do you prefer not what do you think about React and Angular. |
||
9. Browsers are providing options to throttle networks so we can customize the speed of a network. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. More direct answer like You can simulate low speed and high latency networks in DevTools Network Panel would be more accurate. |
||
10. `use strict` helps the developers to write javascript in a secured way and throw errors if they are any undeclared variables. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Secured way? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. strict mode has a lot of differences compared to non-strict mode. I am not sure how to answer the question either. Question should probably be modified |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Native Javascript | ||
1. Write a function which can add all the arguments and return the value ? | ||
Sample Inputs / Outputs | ||
``` | ||
sum(1,2) => 3 | ||
sum(1,2,.3) => 3.3 | ||
|
||
``` | ||
2. Explain the prototypal inheritance? | ||
3. Explain the closures? | ||
4. Difference between `var` ,`let` & `const` ? | ||
5. What would be the output of the following code? | ||
``` | ||
function a(){ | ||
console.log(b); | ||
} | ||
var b=6; | ||
|
||
``` | ||
6. How the javascript engine and Browser handles asynchronous calls | ||
7. Difference between callbacks and promises? | ||
8. Which one do you prefer among React and Angular? | ||
9. How do you simulate the low speed networks? | ||
10. Why the `use strict` is used? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A more ES6 way of doing things would be
or
Using arguments is not considered a good practice anymore.