InterviewSolution
This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.
| 1. |
What Is Require Js? |
Answer»
Require JS includes three main API functions:-
Require JS includes three main API functions:- |
|
| 2. |
How To Install Require Js? |
|
Answer» You can install the latest release of REQUIRE JS from the COMMAND prompt using the below COMMANDS- //Install the Require JS package NPM install -g require js You can install the latest release of Require JS from the command prompt using the below commands- //Install the Require JS package npm install -g require js |
|
| 3. |
Why Do People Use Require Js? What Are The Benefits? |
Answer»
|
|
| 4. |
How To Define Entry Point For Require Js? |
|
Answer» We need to DEFINE an html FILE and it could be "index.html" where Require JS is LOADING i.e. <!DOCTYPE html> <html> <head> <SCRIPT data-main="libs/main" src="libs/require.js"></script> </head> <body> <h1> Require JS Sample APPS</h1> </body> </html> In above example, the data-main attribute of require.js will start initialization of files. We need to define an html file and it could be "index.html" where Require JS is loading i.e. <!DOCTYPE html> <html> <head> <script data-main="libs/main" src="libs/require.js"></script> </head> <body> <h1> Require JS Sample apps</h1> </body> </html> In above example, the data-main attribute of require.js will start initialization of files. |
|
| 5. |
What Are The Main Features Of Require Js? |
Answer»
|
|
| 6. |
What Are Disadvantage Of Require Js? |
| Answer» | |
| 7. |
When Should I Use Require () And When To Use Define ()? |
|
Answer» The define () method looks like:-
define( module_id /*optional*/, [dependencies] /*optional*/, definition function /*function for instantiating the module or object*/ ); And define (['moduleA', 'moduleB'], function (moduleA, moduleB) { //define the module value by returning a value return function () {}; }); The require () method looks like:-
require(['jquery'], function ($) { //jQuery was loaded and can be used now. }); Example 1:- define( 'MyApp', ["marionette"], function (Marionette) { // SET up the app instance var app = new Marionette.Application(); app.on("initialize:after", function(){ console.log("initialize started."); }); // export the app from this module return app; }); Example 2:- // FETCH and EXECUTE Marionette App require( ["MyApp"], function (app) { // Execute App app.start(); }); Example 3:- define({ "root": { "india": "india", "australia": "australia", "england": "england" } }); The define () method looks like:- define( module_id /*optional*/, [dependencies] /*optional*/, definition function /*function for instantiating the module or object*/ ); And define (['moduleA', 'moduleB'], function (moduleA, moduleB) { //define the module value by returning a value return function () {}; }); The require () method looks like:- require(['jquery'], function ($) { //jQuery was loaded and can be used now. }); Example 1:- define( 'MyApp', ["marionette"], function (Marionette) { // set up the app instance var app = new Marionette.Application(); app.on("initialize:after", function(){ console.log("initialize started."); }); // export the app from this module return app; }); Example 2:- // Fetch and execute Marionette App require( ["MyApp"], function (app) { // Execute App app.start(); }); Example 3:- define({ "root": { "india": "india", "australia": "australia", "england": "england" } }); |
|
| 8. |
What Are Asynchronous Module Definition (amd) Modules? |
|
Answer» Defining Modules:-The MODULE is defined USING define () method and it USED for loading the module i.e. define({ country:"India", state: "UP", city: "Noida", userDetail: function () { return "USER Detail"; } }); Defining Functions:- A module can also use a function without dependencies i.e. define(function () { return { country:"India", state: "UP", city: "Noida" } }); Defining Functions with Dependencies:- The Dependencies module looks like. define(["../comp", "../user"], function(comp, user) { return { country:"India", state: "UP", city: "Noida", addUser: function() { comp.decrement(this); user.add(this); } } }); Defining a Module as a Function:- Its looks like. define(["../comp", "../user"], function(comp, user) { return function(userName){ return userName != null ? userName :'NA' } }); Defining a Module with a NAME:- Its looks like. define("Users", ["../comp", "../user"], function(comp, user) { return { country:"India", state: "UP", city: "Noida", addUser: function() { console.log(this); } } }); Defining Modules:-The Module is defined using define () method and it used for loading the module i.e. define({ country:"India", state: "UP", city: "Noida", userDetail: function () { return "User Detail"; } }); Defining Functions:- A module can also use a function without dependencies i.e. define(function () { return { country:"India", state: "UP", city: "Noida" } }); Defining Functions with Dependencies:- The Dependencies module looks like. define(["../comp", "../user"], function(comp, user) { return { country:"India", state: "UP", city: "Noida", addUser: function() { comp.decrement(this); user.add(this); } } }); Defining a Module as a Function:- Its looks like. define(["../comp", "../user"], function(comp, user) { return function(userName){ return userName != null ? userName :'NA' } }); Defining a Module with a Name:- Its looks like. define("Users", ["../comp", "../user"], function(comp, user) { return { country:"India", state: "UP", city: "Noida", addUser: function() { console.log(this); } } }); |
|
| 9. |
What Is Config Function? |
|
Answer» The Require JS can be initialized by passing the main configuration in the HTML template through the data-main attribute. If you want to update the Require JS configuration values with your own configurations value. You can do USING the require js. Config FUNCTION. The configurations options:-
Example looks like:- require.config({ baseUrl: 'scripts/app', paths: { lib: '../lib' }, shim: { 'backbone': { deps: ['underscore'], exports: 'Backbone' } } }); The Require JS can be initialized by passing the main configuration in the HTML template through the data-main attribute. If you want to update the Require JS configuration values with your own configurations value. You can do using the require js. Config function. The configurations options:- Example looks like:- require.config({ baseUrl: 'scripts/app', paths: { lib: '../lib' }, shim: { 'backbone': { deps: ['underscore'], exports: 'Backbone' } } }); |
|
| 10. |
What Is The Project Structure Of Require Js? |
|
Answer» Project DIRECTORY and the structure LOOKS LIKE:-
Project directory and the structure looks like:- |
|
| 11. |
What Is Module In Require Js? |
|
Answer» MODULE is independent unit of program which make easy MAINTENANCE and reusability of code. In RequireJs we TALK about JavaScript module. Module is independent unit of program which make easy maintenance and reusability of code. In RequireJs we talk about JavaScript module. |
|
| 12. |
What Is Data-main Attribute? |
|
Answer» The data-main attribute is an attribute that Require JS will check to start SCRIPT LOADING. The data-main set to the BASE URL for all the scripts. Example:- <!DOCTYPE html> <html> <head> <script data-main="libs/main" src="libs/require.js"></script> </head> <body> <H1> RequireJS Sample apps</h1> </body> </html> The data-main attribute is an attribute that Require JS will check to start script loading. The data-main set to the base URL for all the scripts. Example:- <!DOCTYPE html> <html> <head> <script data-main="libs/main" src="libs/require.js"></script> </head> <body> <h1> RequireJS Sample apps</h1> </body> </html> |
|
| 13. |
What Is Amd Module? |
|
Answer» The AMD is stands for ASYNCHRONOUS Module DEFINITION and is used for defining modules and their dependencies with asynchronous manner. The AMD is stands for Asynchronous Module Definition and is used for defining modules and their dependencies with asynchronous manner. |
|
| 14. |
How To Use Require Js With Jquery? |
|
Answer» The REQUIRE JS USES JQUERY and lots of another dependency i.e. require(['jquery'], function ($) { //jQuery was LOADED and can be USED now. }); The Require JS uses jQuery and lots of another dependency i.e. require(['jquery'], function ($) { //jQuery was loaded and can be used now. }); |
|
| 15. |
What Is The Role Of Optimizer? |
|
Answer» The OPTIMIZER is a built process where your PROJECT is deployed to end USER and its combines all scripts/css files together and minify them. The Optimizer is a built process where your project is deployed to end user and its combines all scripts/css files together and minify them. |
|