Skip to content

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

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Web-Development/Front-end.md
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)
22 changes: 22 additions & 0 deletions 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(){
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.

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

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.

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.

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.

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

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.

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.

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.

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.

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?

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

24 changes: 24 additions & 0 deletions Web-Development/NativeJavascript/questions.md
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?