My interview Experience with EY company
Hello, Hope you doing well. I just gave my interview to EY company on HTML, CSS, JavaScript and Angular.
What's the difference between HTML and HTML5? Why those new tags have been created and the reason behind it?
Can we achieve inheritance in JavaScript?
What is closure? Example of closure?
Deep Copy and Shallow Copy with example?
Bind, apply and call methods in JavaScript with example
Why there will be *(ngIf,ngFor) on structural directives in angular?
What are directives in angular? their types.
What does this context in the function? How does it differ from this context in the different scope?
Answer Q1- What's the difference between HTML and HTML5? Why those new tags have been created and the reason behind them?
Html vs html5 It doesn't allow the JavaScript to run on the browser
It allows JavaScript to run on the browser
It doesn't support video and audio without the help of the Flash player support It does support using tags.
It uses cookies to store the temporary data. It uses SQL database and application cache to store the data.
The doctype declaration is too long and complicated. Doctype declaration is quite simple and easy.
HTML, body and head tags are mandatory while writing the HTML code. tags are not mandatory while writing the code.
Q2 - Can we achieve inheritance in JavaScript?
Inheritance can be achieved through prototype chaining in JavaScript. Every variable and method is treated as an object in JavaScript. Each object/method created has access to the prototype object. When it tries to find out its property, it traverses through each of its object prototypes until its prototype of the prototype is reached null.
Q3 - What is closure? Example of closure?
Closure is the combination of a function bundled together concerning its surrounding state meaning the inner function can access the variable declared at its outer scope.
example function
closureExample(){ var a = 10; function innerfunction(){ console.log(a) } }
variable a is being accessed inside the inner function.
Q4 - Deep Copy and Shallow Copy with example?
Assigning the same value to a new variable makes a copy in the programming language.
Shallow Copy: A copy to a new variable always connects with the old variable meaning the reference will be the same for both variables. Changing the value of one variable changes the value of another variable. The example is shown in the below picture.
Deep Copy: A copy to a new variable disconnects with the old variable meaning the reference will be different for both variables. Changing the value of one variable will not change the value of another variable. The example is shown in the below picture.
NOTE: Primitive datatypes in javascript don't create shallow copy, they always make the real copy (deep copy).
NOTE: Another datatype like arrays, or objects will make shallow copy by default. A deep copy can be achieved by following operators in javascript
Reference link - https://www.freecodecamp.org/news/copying-stuff-in-javascript-how-to-differentiate-between-deep-and-shallow-copies-b6d8c1ef09cd/
Spread operator (...): same for the arrays
Object. assign(): same for the arrays.
Q5 - Bind, apply and call methods in JavaScript with an examples
Apply and Call will change the context of the function. It changes the value "this" context with the value provided in the function. The only difference between the two function is that Apply takes an array as an argument where Call takes a string as an argument with one after the other separated by comma.
Bind creates a new function with provided this context which can be executed later.
Example of Call method
Example of Apply Method
Example of Bind Method
Q6 - Why there will be *(ngIf,ngFor) on structural directives in angular?
Structural directives always be prefixed by an asterisk such as ngIf,*ngFor. It is a shorthand convention that Angular interprets and converts into longer forms.
<div *ngIf\="hero" class="name">{{hero.name}}</div>
converts to below code snippet
<ng-template [ngIf]="hero">
<div class="name">{{hero.name}}</div>
</ng-template>
Q7 - What does this context in the function? How does it differ from this context in the different scope?
In Javascript, this keyword refers to an object, which object depends on how "this" is being invoked.
this in a Method:- When used in an object method, this
refers to the object.
const person = {
firstName: "John",
lastName : "Doe",
id : 5566,
fullName : function() {
return this.firstName + " " + this.lastName;
}
};
this alone:- When used alone, this
refers to the global object.
this in a Function:- In a function, the global object is the default binding for this
this in a Function(strict):- JavaScript strict mode does not allow default binding.In strict mode, this
is undefined
.
this in Event Handler:- In HTML event handlers, this
refers to the HTML element that received the event.