Skip to content
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

Frontendquestions #4

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

rohinikumar4073
Copy link

No description provided.

@request-info
Copy link

request-info bot commented Feb 12, 2018

The maintainers of this repository would appreciate it if you could provide more information.

@rohinikumar4073
Copy link
Author

Added interview questions and answers for Native javascript in frontend.

Copy link

@praveenpuglia praveenpuglia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, I feel the answers can be improved to include more direct information.

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.
5. b will be `undefined` as only the variables are hoisted but not the assignment.
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.
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.

Choose a reason for hiding this comment

The 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.

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.
8. React more developer friendly and Angular build on solid software principles like MVC and dependency injection.
9. Browsers are providing options to throttle networks so we can customize the speed of a network.
10. `use strict` helps the developers to write javascript in a secured way and throw errors if they are any undeclared variables.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Secured way?

# Answers to the frontend questions Native script
1.
```
function sum(){
Copy link

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

function sum(...args) {
  return args.reduce((a, b) => a + b);
}

or

function sum(...args) {
  let sum = 0;
  for (let i of args) {
    sum += i; 
  }
  return sum;
}

Using arguments is not considered a good practice anymore.

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.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is kind of gibberish.

}
```
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.
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.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand the intent but this is very poor way to write.

```
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.
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.
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.
Copy link

Choose a reason for hiding this comment

The 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 let and const. There is no term called "simple properties". Even if you meant that properties owned by the object it's still false.

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.
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.
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.
5. b will be `undefined` as only the variables are hoisted but not the assignment.
Copy link

Choose a reason for hiding this comment

The 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.

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.
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.
5. b will be `undefined` as only the variables are hoisted but not the assignment.
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.
Copy link

Choose a reason for hiding this comment

The 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

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.
5. b will be `undefined` as only the variables are hoisted but not the assignment.
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.
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.
Copy link

Choose a reason for hiding this comment

The 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.

5. b will be `undefined` as only the variables are hoisted but not the assignment.
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.
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.
8. React more developer friendly and Angular build on solid software principles like MVC and dependency injection.
Copy link

Choose a reason for hiding this comment

The 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.

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.
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.
8. React more developer friendly and Angular build on solid software principles like MVC and dependency injection.
9. Browsers are providing options to throttle networks so we can customize the speed of a network.
Copy link

Choose a reason for hiding this comment

The 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.

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.
8. React more developer friendly and Angular build on solid software principles like MVC and dependency injection.
9. Browsers are providing options to throttle networks so we can customize the speed of a network.
10. `use strict` helps the developers to write javascript in a secured way and throw errors if they are any undeclared variables.
Copy link

Choose a reason for hiding this comment

The 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

@rohinikumar4073
Copy link
Author

Thanks for the feedback, I just updated answers please have a look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants