Q1. What is fat arrow function in A9 + ?
Q2. What is AOT? and what is the use of AOT in angular 9 ?
Q3. Limitation of AOT compiler?
Q4. Explain the difference between JIT vs AOT?
Q5. Relation between components and directives in angular 2?
----------------------------------------------------------------------------------------------------------------Q2. What is AOT? and what is the use of AOT in angular 9 ?
Q3. Limitation of AOT compiler?
Q4. Explain the difference between JIT vs AOT?
Q5. Relation between components and directives in angular 2?
Q1. What is fat arrow function in A9 + ?
Answer:
This is a feature of ES6. They are one-line mini functions which work much like Lambdas in other languages like C#.
By using arrow function we avoid having to type the function keyword, return keyword (it’s implicit in arrow functions), and curly brackets.
Try to read till end. Examples at the end are important.
//Syntax in es5
var multiplyValue = function(x,y){
return x * y;
}
//Syntax in es6 using arrow
var multiplyValue = (x,y) => {return x*y;};
//Simplified arrow, When returning only single line statement.
var multiplyValue = (x,y) => x*y;
//Simplified arrow, When only single input
var squareValue = function (x){
return x*x;
}
var squareValue = x => x*x;
//Simplified arrow, When no input
var returnOnly = function (){
return "I am string";
}
var returnOnly = () => "I am string";
// When using for object
var useObject = function (first, last){
return {
firstName : first,
lastName: last
}
}
var useObject = (first, last) => {firstName:first, lastName: last};
// Promises and Callbacks in ES5
aAsync()
.then(function() {
return bAsync();
}).then(function() {
return cAsync();
}).done(function() {
finish();
});
// es6
aAsync()
.then(() => bAsync())
.then(() => cAsync())
.done(() => finish);
https://www.sitepoint.com/es6-arrow-functions-new-fat-concise-syntax-javascript/
---------------------------------------------------------------------------------
Q2. What is AOT? and what is the use of AOT in angular 9 ?
Answer:
The Angular Ahead-of-Time (AOT) compiler complies your Angular HTML and Type Script code into efficient JavaScript code during the build phase before the browser downloads and runs that code. While in Just-in-Time (JIT) approach, browser compiles the code in browser.
Just-in-Time (JIT), which compiles your app in the browser at runtime. This was the default until Angular 8.
Ahead-of-Time (AOT), which compiles your app and libraries at build time. This is the default since Angular 9.
-------------------------------------------------------------------------------------------------------------------
Q3. Limitation of AOT compiler?
Answer:
Sometimes for complex medium sized project, the compiled code is even larger than JIT compiled code.
-------------------------------------------------------------------------------------------------------------------
Q4. Explain the difference between JIT vs AOT?
Answer:
1) JIT is juts in time compilation and as the name implies, it compiles the application just in time in browser at run time. it means jit packages the vendor.js having angular compiler to compile all JavaScript and angular code as a part of bundle.
1) Where as the AOT, ahead of time compilation. compiles the application at build time. Means AOT will bundle without angular compiler as browser does not need to download the angular compiler and do the compilation. browser already received compiled code.
2) Default compiler of Angular 2 is JIT (Just-in-Time) compiler but production build is default AOT.
3) ng build or ng serve give JIT compilation. (ng build or ng serve --aot true) give aot compilation.
4) With JIT you see error only at run time. means only at browser level when browser done the compilation u see error in console. With AOT compilation, you will see error even at build time.
4) With JIT you see error only at run time. means only at browser level when browser done the compilation u see error in console. With AOT compilation, you will see error even at build time.
Check out the flow of events for JIT and AOT in below link
http://blog.mgechev.com/2016/08/14/ahead-of-time-compilation-angular-offline-precompilation/
-----------------------------------------------------------------------------------------------------------------------
Q5. Relation between components and directives in angular 2?
Answer:
Component is a type of directives in angular 2.
There are three types of directives possible in angular 2
Structural directives changes the structure like *ngFor and *ngIF.
-------------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------
Q5. Relation between components and directives in angular 2?
Answer:
Component is a type of directives in angular 2.
There are three types of directives possible in angular 2
- Attribute
- Structural and
- Component.
Attribute directives changes the attributes of element like *ngStyle.
Structural directives changes the structure like *ngFor and *ngIF.
-------------------------------------------------------------------------------------------------------------------------
No comments:
Post a Comment