\n \n\n\n```"}},{"@type":"Question","name":"What is scope in AngularJS?","acceptedAnswer":{"@type":"Answer","text":"Scope is a JavaScript object that refers to the application model. It acts as a context for evaluating angular expressions. Basically, it acts as glue between controller and view.\n\nScopes are hierarchical in nature and follow the DOM structure of your AngularJS app. AngularJS has two scope objects: **$rootScope** and **$scope**."}},{"@type":"Question","name":" What is `$scope` and `$rootScope`?","acceptedAnswer":{"@type":"Answer","text":"**$scope** - A $scope is a JavaScript object which is used for communication between controller and view. Basically, $scope binds a view (DOM element) to the model and functions defined in a controller.\n\n**$rootScope** - The $rootScope is the top-most scope. An app can have only one $rootScope which will be shared among all the components of an app. Hence it acts like a global variable. All other $scopes are children of the $rootScope.\nFor example, suppose you have two controllers: Ctrl1 and Ctrl2 as given below:\n\n```html\n\n\n \n
Hello {{msg}}!\n
\n Hello {{name}}! (rootScope) \n
\n
\n
\n Hello {{msg}}!
\n Hey {{myName}}!
\n Hi {{name}}! (rootScope) \n
\n \n \n \n\n```\n"}},{"@type":"Question","name":"What is _scope hierarchy_?","acceptedAnswer":{"@type":"Answer","text":"The **$scope** object used by views in AngularJS are organized into a hierarchy. There is a root scope, and the **$rootScope** can has one or more child scopes. Each controller has its own **$scope** (which is a child of the **$rootScope**), so whatever variables you create on $scope within controller, these variables are accessible by the view based on this controller.\n\nFor example, suppose you have two controllers: ParentController and ChildController as given below:\n```html\n\n \n \n \n \n \n
\n \n \n \n \n \n \n \n \n \n \n \n \n \n
Parent Controller
Manager Name{{managerName}}
Company Name{{companyName}}
\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
Child Controller
Team Lead Name{{ teamLeadName }}
Reporting To{{managerName}}
Company Name{{companyName}}
\n
\n
\n \n\n```\n"}},{"@type":"Question","name":"What is the difference between `$scope` and `scope`?","acceptedAnswer":{"@type":"Answer","text":"The module factory methods like controller, directive, factory, filter, service, animation, config and run receive arguments through dependency injection (DI). In case of DI, you inject the **scope object** with the dollar prefix i.e. **$scope**. The reason is the **injected arguments** must match to the names of **injectable objects** followed by dollar ($) prefix.\n**For example**, you can inject the scope and element objects into a controller as given below:\n\n```javascript\nmodule.controller('MyController', function ($scope, $element) { // injected arguments });\n```\n\nWhen the methods like directive linker function don’t receive arguments through dependency injection, you just pass the **scope object** without using dollar prefix i.e. **scope**. The reason is the passing arguments are received by its caller.\n\n```javascript\nmodule.directive('myDirective', function () // injected arguments here {\n return {\n // linker function does not use dependency injection\n link: function (scope, el, attrs) {\n\t// the calling function will passes the three arguments to the linker: scope, element and attributes, in the same order\n\t} };\n});\n```\n\nIn the case of non-dependency injected arguments, you can give the name of injected objects as you wish. The above code can be re-written as:\n\n```javascript\nmodule.directive(\"myDirective\", function () {\n\treturn {\n link: function (s, e, a) {\n // s == scope\n\t} };\n});\n// e == element\n```\n\nIn short, in case of DI the **scope object** is received as **$scope** while in case of non-DI **scope object** is received as **scope** or with any name."}},{"@type":"Question","name":"How AngularJS is compiled?","acceptedAnswer":{"@type":"Answer","text":"Angular's HTML compiler allows you to teach the browser new HTML syntax. The compiler allows you to attach new behaviors or attributes to any HTML element. Angular calls these behaviors as directives.\nAngularJS compilation process takes place in the web browser; no server side or pre-compilation step is involved.\nAngular uses $compiler service to compile your angular HTML page. The angular' compilation process begins after your HTML page (static DOM) is fully loaded. It happens in two phases:\n\n1. *Compile* - It traverse the DOM and collect all of the directives. The result is a linking function.\n2. *Link* - It combines the directives with a scope and produces a live view. Any changes in the scope model are reflected in the view, and any user interactions with the view are reflected in the scope model.\n\nThe concept of compile and link comes from C language, where you first compile the code and then link it to actually execute it. The process is very much similar in AngularJS as well."}},{"@type":"Question","name":"How AngularJS compilation is different from other JavaScript frameworks?","acceptedAnswer":{"@type":"Answer","text":"If you have worked on templates in other java script framework/library like backbone and jQuery, they process the template as a string and result as a string. You have to dumped this result string into the DOM where you wanted it with **innerHTML()**.\n\nAngularJS process the template in another way. It directly works on HTML DOM rather than strings and manipulates it as required. It uses two way data-binding between model and view to sync your data."}},{"@type":"Question","name":"What are _Compile_, _Pre_ and _Post_ linking in AngularJS?","acceptedAnswer":{"@type":"Answer","text":"* *Compile* – This compiles an HTML string or DOM into a template and produces a template function, which\ncan then be used to link scope and the template together.\nUse the compile function to change the original DOM (template element) before AngularJS creates an instance of it and before a scope is created.\n\n* *Post-Link* – This is executed after the child elements are linked. It is safe to do DOM transformation in the post- linking function.\nUse the post-link function to execute logic, knowing that all child elements have been compiled and all pre-link and post-link functions of child elements have been executed.\n\n* *Pre-Link* – This is executed before the child elements are linked. Not safe to do DOM transformation since the compiler linking function will fail to locate the correct elements for linking.\nUse the pre-link function to implement logic that runs when AngularJS has already compiled the child elements, but before any of the child element's post-link functions have been called.\n\n\n```html\n\n \n Compile vs Link\n \n \n \n \n \n \n \n Hello {{name}}\n \n \n \n \n\n```\n\nOutput:\n\n```shell\nlevel-One: compile\nlevel-Two: compile\nlevel-Three: compile\nlevel-One: pre link\nlevel-Two: pre link\nlevel-Three: pre link\nlevel-Three: post link\nlevel-Two: post link\nlevel-One: post link\n```"}},{"@type":"Question","name":"Explain what is _injector_?","acceptedAnswer":{"@type":"Answer","text":"*An injector* is a service locator. It is used to retrieve object instances as defined by provider, instantiate types, invoke methods and load modules. There is a single injector per Angular application, it helps to look up an object instance by its name."}},{"@type":"Question","name":"How do you share data between controllers?","acceptedAnswer":{"@type":"Answer","text":"Create an AngularJS service that will hold the data and inject it inside of the controllers.\n\nUsing a service is the cleanest, fastest and easiest way to test. However, there are couple of other ways to implement data sharing between controllers, like:\n\n– Using `events` \n– Using `$parent`, `nextSibling`, `controllerAs`, etc. to directly access the controllers \n– Using the `$rootScope` to add the data on (not a good practice)\n\nThe methods above are all correct, but are not the most efficient and easy to test."}},{"@type":"Question","name":"What is the difference between `ng-show`/`ng-hide` and `ng-if` directives?","acceptedAnswer":{"@type":"Answer","text":"`ng-show`/`ng-hide` will always insert the DOM element, but will display/hide it based on the condition. `ng-if` will not insert the DOM element until the condition is not fulfilled.\n\n`ng-if` is better when we needed the DOM to be loaded conditionally, as it will help load page bit faster compared to `ng-show`/`ng-hide`.\n\nWe only need to keep in mind what the difference between these directives is, so deciding which one to use totally depends on the task requirements.\n"}},{"@type":"Question","name":"Explain how `$scope.$apply()` works?","acceptedAnswer":{"@type":"Answer","text":"`$scope.$apply` re-evaluates all the declared ng-models and applies the change to any that have been altered (i.e. assigned to a new value) Explanation: scope.scope.scope.apply() is one of the core angular functions that should never be used explicitly, it forces the angular engine to run on all the watched variables and all external variables and apply the changes on their values"}},{"@type":"Question","name":"What makes the `angular.copy()` method so powerful?","acceptedAnswer":{"@type":"Answer","text":"It creates a deep copy of the variable.\n\nA deep copy of a variable means it doesn’t point to the same memory reference as that variable. Usually assigning one variable to another creates a “shallow copy”, which makes the two variables point to the same memory reference. Therefore if one is changed, the other changes as well."}},{"@type":"Question","name":"How would you make an Angular service return a promise?","acceptedAnswer":{"@type":"Answer","text":"To add promise functionality to a service, we inject the “$q” dependency in the service, and then use it like so:\n```js\nangular.factory('testService', function($q) {\n return {\n getName: function() {\n var deferred = $q.defer();\n\n //API call here that returns data\n testAPI.getName().then(function(name) {\n deferred.resolve(name);\n });\n\n return deferred.promise;\n }\n };\n});\n```\n\nThe `$q` library is a helper provider that implements promises and deferred objects to enable asynchronous functionality."}},{"@type":"Question","name":"How do you reset a `$timeout`, `$interval()`, and disable a `$watch()`?","acceptedAnswer":{"@type":"Answer","text":"To reset a `timeout` and/or `$interval`, assign the result of the function to a variable and then call the `.cancel()` function:\n\n```js\nvar customTimeout = $timeout(function () {\n\t// arbitrary code\n}, 55);\n\n$timeout.cancel(customTimeout);\n``` \n\nTo disable `$watch()`, we call its deregistration function. `$watch()` then returns a deregistration function that we store to a variable and that will be called for cleanup:\n\n```js\nvar deregisterWatchFn = $scope.$on('$destroy', function() {\n // we invoke that deregistration function, to disable the watch\n deregisterWatchFn();\n});\n```"}},{"@type":"Question","name":"Explain what is a `$scope` in AngularJS?","acceptedAnswer":{"@type":"Answer","text":"**Scope** is an object that refers to the application model. It is an execution context for expressions. Scopes are arranged in hierarchical structure which mimic the DOM structure of the application. Scopes can watch expressions and propagate events. Scopes are objects that refer to the model. They act as glue between controller and view."}},{"@type":"Question","name":"What is _DDO_ (Directive Definition Object)?","acceptedAnswer":{"@type":"Answer","text":"**DDO** is an object used while creating a custome directive. A standard DDO object has following parameters.\n\n```js\nvar directiveDefinitionObject = {\n\tpriority: 0,\n\ttemplate: '
', // or // function(tElement, tAttrs) { ... },\n\t// or\n\t// templateUrl: 'directive.html', // or // function(tElement, tAttrs) { ... },\n\ttransclude: false,\n\trestrict: 'A',\n\ttemplateNamespace: 'html',\n\tscope: false,\n\tcontroller: function (\n\t\t$scope,\n\t\t$element,\n\t\t$attrs,\n\t\t$transclude,\n\t\totherInjectables\n\t) { ...\n\t},\n\tcontrollerAs: 'stringIdentifier',\n\tbindToController: false,\n\trequire: 'siblingDirectiveName', // or // ['^parentDirectiveName', '?optionalDirectiveName', '?^optionalParent'],\n\tcompile: function compile(tElement, tAttrs, transclude) {\n\t\treturn {\n\t\t\tpre: function preLink(scope, iElement, iAttrs, controller) { ...\n\t\t\t},\n\t\t\tpost: function postLink(scope, iElement, iAttrs, controller) { ...\n\t\t\t}\n\t\t};\n\t\t// or\n\t\t// return function postLink( ... ) { ... }\n\t}\n\t// or\n\t// link: {\n\t// pre: function preLink(scope, iElement, iAttrs, controller) { ... },\n\t// post: function postLink(scope, iElement, iAttrs, controller) { ... }\n\t// }\n\t// or\n\t// link: function postLink( ... ) { ... }\n};\n```"}},{"@type":"Question","name":"How do you hide an HTML element via a button click in AngularJS?","acceptedAnswer":{"@type":"Answer","text":"This can be done by using the `ng-hide` directive in conjunction with a controller to hide an HTML element on button click.\n\n```html\n
\n \n

Hello World!

\n
\n```\n\n```js\nfunction MyCtrl($scope) {\n\t$scope.isHide = false;\n\t$scope.hide = function () {\n\t\t$scope.isHide = true;\n\t};\n}\n```\n "}},{"@type":"Question","name":"What is the difference between `==` and `===`?","acceptedAnswer":{"@type":"Answer","text":"`==` is the abstract equality operator while `===` is the strict equality operator. The `==` operator will compare for equality after doing any necessary type conversions. The `===` operator will not do type conversion, so if two values are not the same type `===` will simply return `false`. When using `==`, funky things can happen, such as:\n\n```js\n1 == '1'; // true\n1 == [1]; // true\n1 == true; // true\n0 == ''; // true\n0 == '0'; // true\n0 == false; // true\n```\n\nMy advice is never to use the `==` operator, except for convenience when comparing against `null` or `undefined`, where `a == null` will return `true` if `a` is `null` or `undefined`.\n\n```js\nvar a = null;\nconsole.log(a == null); // true\nconsole.log(a == undefined); // true\n```"}},{"@type":"Question","name":"Why is extending built-in JavaScript objects not a good idea?","acceptedAnswer":{"@type":"Answer","text":"Extending a built-in/native JavaScript object means adding properties/functions to its `prototype`. While this may seem like a good idea at first, it is dangerous in practice. Imagine your code uses a few libraries that both extend the `Array.prototype` by adding the same `contains` method, the implementations will overwrite each other and your code will break if the behavior of these two methods is not the same.\n\nThe only time you may want to extend a native object is when you want to create a polyfill, essentially providing your own implementation for a method that is part of the JavaScript specification but might not exist in the user's browser due to it being an older browser."}}]}
FullStackFSCCafé
 
 
Sign in with GoogleSign in with Google. Opens in new tab
Kill Your Tech Interview
3877 Full-Stack, Algorithms & System Design Interview Questions
Answered To Get Your Next Six-Figure Job Offer
      
🤖 Having Machine Learning & DS Interview? Check  MLStack.Cafe - 1704 Data Science & ML Interview Questions & Answers!Having ML & DS Interview? Check 🤖 MLStack.Cafe - 1704 ML & DS Interview Questions and Answers

Top 29 AngularJS Interview Questions (ANSWERED) You Will Be Asked Tomorrow

The average annual pay for an AngularJS Developer Job in the US is $112749 a year. If you are already proficient in Javascript, AngularJS is a great addition to your arsenal. AngularJS is a framework for dynamic web apps. Grab some coffee and check the Top advanced 29 AngularJS interview questions experienced web developers may be asked on a next tech interview.

Q1: 
What is typeof operator?

Answer

JavaScript provides a typeof operator that can examine a value and tell you what type it is:

var a;
typeof a;				// "undefined"

a = "hello world";
typeof a;				// "string"

a = 42;
typeof a;				// "number"

a = true;
typeof a;				// "boolean"

a = null;
typeof a;				// "object" -- weird, bug

a = undefined;
typeof a;				// "undefined"

a = { b: "c" };
typeof a;				// "object"

Having Tech or Coding Interview? Check 👉 179 JavaScript Interview Questions

Q2: 
What is the difference between ng-show/ng-hide and ng-if directives?

Answer

ng-show/ng-hide will always insert the DOM element, but will display/hide it based on the condition. ng-if will not insert the DOM element until the condition is not fulfilled.

ng-if is better when we needed the DOM to be loaded conditionally, as it will help load page bit faster compared to ng-show/ng-hide.

We only need to keep in mind what the difference between these directives is, so deciding which one to use totally depends on the task requirements.


Having Tech or Coding Interview? Check 👉 61 AngularJS Interview Questions
Source: codementor.io

Q3: 
Why to use AngularJS?

Answer

There are following reasons to choose AngularJS as a web development framework:

  1. It is based on MVC pattern which helps you to organize your web apps or web application properly.
  2. It extends HTML by attaching directives to your HTML markup with new attributes or tags and expressions in order to define very powerful templates.
  3. It also allows you to create your own directives, making reusable components that fill your needs and abstract your DOM manipulation logic.
  4. It supports two-way data binding i.e. connects your HTML (views) to your JavaScript objects (models) seamlessly. In this way any change in model will update the view and vice versa without any DOM manipulation or event handling.
  5. It encapsulates the behavior of your application in controllers which are instantiated with the help of dependency injection.
  6. It supports services that can be injected into your controllers to use some utility code to fullfil your need. For example, it provides $http service to communicate with REST service.
  7. It supports dependency injection which helps you to test your angular app code very easily.
  8. Also, AngularJS is mature community to help you. It has widely support over the internet.

Having Tech or Coding Interview? Check 👉 61 AngularJS Interview Questions

Q4: 
Explain what is a $scope in AngularJS?

Answer

Scope is an object that refers to the application model. It is an execution context for expressions. Scopes are arranged in hierarchical structure which mimic the DOM structure of the application. Scopes can watch expressions and propagate events. Scopes are objects that refer to the model. They act as glue between controller and view.


Having Tech or Coding Interview? Check 👉 61 AngularJS Interview Questions
Source: codementor.io

Q5: 
How do you hide an HTML element via a button click in AngularJS?

Answer

This can be done by using the ng-hide directive in conjunction with a controller to hide an HTML element on button click.

<div ng-controller="MyCtrl">
    <button ng-click="hide()">Hide element</button>
    <p ng-hide="isHide">Hello World!</p>
</div>
function MyCtrl($scope) {
	$scope.isHide = false;
	$scope.hide = function () {
		$scope.isHide = true;
	};
}

Having Tech or Coding Interview? Check 👉 61 AngularJS Interview Questions
Source: codementor.io

Q6: 
How do you share data between controllers?

Answer

Create an AngularJS service that will hold the data and inject it inside of the controllers.

Using a service is the cleanest, fastest and easiest way to test. However, there are couple of other ways to implement data sharing between controllers, like:

– Using events
– Using $parent, nextSibling, controllerAs, etc. to directly access the controllers
– Using the $rootScope to add the data on (not a good practice)

The methods above are all correct, but are not the most efficient and easy to test.


Having Tech or Coding Interview? Check 👉 61 AngularJS Interview Questions
Source: codementor.io

Q7: 
What are Directives in AngularJS?

Answer

AngularJS directives are a combination of AngularJS template markups (HTML attributes or elements, or CSS classes) and supporting JavaScript code. The JavaScript directive code defines the template data and behaviors of the HTML elements.

AngularJS directives are used to extend the HTML vocabulary i.e. they decorate html elements with new behaviors and help to manipulate html elements attributes in interesting way.

There are some built-in directives provided by AngularJS like as ng-app, ng-controller, ng-repeat, ng-model etc.


Having Tech or Coding Interview? Check 👉 61 AngularJS Interview Questions

Q8: 
What are Filters in AngularJS?

Answer

Filters are used to format data before displaying it to the user. They can be used in view templates, controllers, services and directives. There are some built-in filters provided by AngularJS like as Currency, Date, Number, OrderBy, Lowercase, Uppercase etc. You can also create your own filters.

Filter Syntax:

{{ expression | filter}}


Having Tech or Coding Interview? Check 👉 61 AngularJS Interview Questions
🤖 Having Machine Learning & DS Interview? Check  MLStack.Cafe - 1704 Data Science & ML Interview Questions & Answers!Having ML & DS Interview? Check 🤖 MLStack.Cafe - 1704 ML & DS Interview Questions and Answers

Q9: 
What are the AngularJS features?

Answer

The features of AngularJS are listed below:

  1. Modules
  2. Directives
  3. Templates
  4. Scope
  5. Expressions
  6. Data Binding
  7. MVC (Model, View & Controller)
  8. Validations
  9. Filters
  10. Services
  11. Routing
  12. Dependency Injection
  13. Testing

Having Tech or Coding Interview? Check 👉 61 AngularJS Interview Questions

Q10: 
What is scope hierarchy?

Answer

The $scope object used by views in AngularJS are organized into a hierarchy. There is a root scope, and the $rootScope can has one or more child scopes. Each controller has its own $scope (which is a child of the $rootScope), so whatever variables you create on $scope within controller, these variables are accessible by the view based on this controller.

For example, suppose you have two controllers: ParentController and ChildController as given below:

<html>
  <head>
    <script src="lib/angular.js"></script>
    <script>
      var app = angular.module('ScopeChain', []); app.controller("parentController", function ($scope) {
      	$scope.managerName = 'Shailendra Chauhan';
      	$scope.$parent.companyName = 'Dot Net Tricks'; //attached to $rootScope
      });
      app.controller("childController", function ($scope, $controller) {
                 $scope.teamLeadName = 'Deepak Chauhan';
             });
         
    </script>
  </head>
  <body ng-app="ScopeChain">
    <div ng-controller="parentController ">
      <table style="border:2px solid #e37112">
        <caption>Parent Controller</caption>
        <tr>
          <td>Manager Name</td>
          <td>{{managerName}}</td>
        </tr>
        <tr>
          <td>Company Name</td>
          <td>{{companyName}}</td>
        </tr>
        <tr>
          <td>
            <table ng-controller="childController" style="border:2px solid #428bca">
              <caption>Child Controller</caption>
              <tr>
                <td>Team Lead Name</td>
                <td>{{ teamLeadName }}</td>
              </tr>
              <tr>
                <td>Reporting To</td>
                <td>{{managerName}}</td>
              </tr>
              <tr>
                <td>Company Name</td>
                <td>{{companyName}}</td>
              </tr>
            </table>
          </td>
        </tr>
      </table>
    </div>
  </body>
</html>

Having Tech or Coding Interview? Check 👉 61 AngularJS Interview Questions

Q11: 
What is strict mode?

Answer

Strict Mode is a new feature in ECMAScript 5 that allows you to place a program, or a function, in a "strict" operating context. This strict context prevents certain actions from being taken and throws more exceptions.

// Non-strict code...

(function(){
  "use strict";

  // Define your library strictly...
})();

// Non-strict code...

Having Tech or Coding Interview? Check 👉 179 JavaScript Interview Questions

Q12: 
What is auto bootstrap process in AngularJS?

Answer

Angular initializes automatically upon DOMContentLoaded event or when the angular.js script is downloaded to the browser and the document.readyState is set to complete. At this point AngularJS looks for the ng-app directive which is the root of angular app compilation and tells about AngularJS part within DOM. When the ng-app directive is found then Angular will:

  1. Load the module associated with the directive.
  2. Create the application injector.
  3. Compile the DOM starting from the ng-app root element. This process is called auto-bootstrapping.
<html>
<body ng-app="myApp">
<div ng-controller="Ctrl"> Hello {{msg}}!
</div>
    <script src="lib/angular.js"></script>
    <script>
var app = angular.module('myApp', []); app.controller('Ctrl', function ($scope) {
              $scope.msg = 'World';
          });
    </script>
</body>
</html>

Having Tech or Coding Interview? Check 👉 61 AngularJS Interview Questions

Q13: 
What is scope in AngularJS?

Answer

Scope is a JavaScript object that refers to the application model. It acts as a context for evaluating angular expressions. Basically, it acts as glue between controller and view.

Scopes are hierarchical in nature and follow the DOM structure of your AngularJS app. AngularJS has two scope objects: $rootScope and $scope.


Having Tech or Coding Interview? Check 👉 61 AngularJS Interview Questions

Q14: 
What is the difference between == and ===?

Answer

== is the abstract equality operator while === is the strict equality operator. The == operator will compare for equality after doing any necessary type conversions. The === operator will not do type conversion, so if two values are not the same type === will simply return false. When using ==, funky things can happen, such as:

1 == '1'; // true
1 == [1]; // true
1 == true; // true
0 == ''; // true
0 == '0'; // true
0 == false; // true

My advice is never to use the == operator, except for convenience when comparing against null or undefined, where a == null will return true if a is null or undefined.

var a = null;
console.log(a == null); // true
console.log(a == undefined); // true

Having Tech or Coding Interview? Check 👉 179 JavaScript Interview Questions

Q15: 
Could you explain the difference between ES5 and ES6

Answer
  • ECMAScript 5 (ES5): The 5th edition of ECMAScript, standardized in 2009. This standard has been implemented fairly completely in all modern browsers

  • ECMAScript 6 (ES6)/ ECMAScript 2015 (ES2015): The 6th edition of ECMAScript, standardized in 2015. This standard has been partially implemented in most modern browsers.

Here are some key differences between ES5 and ES6:

  • Arrow functions & string interpolation:
    Consider:
const greetings = (name) => {
      return `hello ${name}`;
}

and even:

const greetings = name => `hello ${name}`;
  • Const.
    Const works like a constant in other languages in many ways but there are some caveats. Const stands for ‘constant reference’ to a value. So with const, you can actually mutate the properties of an object being referenced by the variable. You just can’t change the reference itself.
const NAMES = [];
NAMES.push("Jim");
console.log(NAMES.length === 1); // true
NAMES = ["Steve", "John"]; // error
  • Block-scoped variables.
    The new ES6 keyword let allows developers to scope variables at the block level. Let doesn’t hoist in the same way var does.
  • Default parameter values Default parameters allow us to initialize functions with default values. A default is used when an argument is either omitted or undefined — meaning null is a valid value.
// Basic syntax
function multiply (a, b = 2) {
     return a * b;
}
multiply(5); // 10
  • Class Definition and Inheritance
    ES6 introduces language support for classes (class keyword), constructors (constructor keyword), and the extend keyword for inheritance.

  • for-of operator
    The for...of statement creates a loop iterating over iterable objects.

  • Spread Operator For objects merging
const obj1 = { a: 1, b: 2 }
const obj2 = { a: 2, c: 3, d: 4}
const obj3 = {...obj1, ...obj2}
  • Promises
    Promises provide a mechanism to handle the results and errors from asynchronous operations. You can accomplish the same thing with callbacks, but promises provide improved readability via method chaining and succinct error handling.
const isGreater = (a, b) => {
  return new Promise ((resolve, reject) => {
    if(a > b) {
      resolve(true)
    } else {
      reject(false)
    }
    })
}
isGreater(1, 2)
  .then(result => {
    console.log('greater')
  })
 .catch(result => {
    console.log('smaller')
 })
  • Modules exporting & importing Consider module exporting:
const myModule = { x: 1, y: () => { console.log('This is ES5') }}
export default myModule;

and importing:

import myModule from './myModule';

Having Tech or Coding Interview? Check 👉 179 JavaScript Interview Questions
🤖 Having Machine Learning & DS Interview? Check  MLStack.Cafe - 1704 Data Science & ML Interview Questions & Answers!Having ML & DS Interview? Check 🤖 MLStack.Cafe - 1704 ML & DS Interview Questions and Answers

Q16: 
How do you reset a $timeout, $interval(), and disable a $watch()?

Answer

To reset a timeout and/or $interval, assign the result of the function to a variable and then call the .cancel() function:

var customTimeout = $timeout(function () {
	// arbitrary code
}, 55);

$timeout.cancel(customTimeout);

To disable $watch(), we call its deregistration function. $watch() then returns a deregistration function that we store to a variable and that will be called for cleanup:

var deregisterWatchFn = $scope.$on('$destroy', function() {
  // we invoke that deregistration function, to disable the watch
  deregisterWatchFn();
});

Having Tech or Coding Interview? Check 👉 61 AngularJS Interview Questions
Source: codementor.io

Q17: 
How would you make an Angular service return a promise?

Problem

Write a code snippet as an example

Answer

To add promise functionality to a service, we inject the “$q” dependency in the service, and then use it like so:

angular.factory('testService', function($q) {
  return {
    getName: function() {
      var deferred = $q.defer();

      //API call here that returns data
      testAPI.getName().then(function(name) {
        deferred.resolve(name);
      });

      return deferred.promise;
    }
  };
});

The $q library is a helper provider that implements promises and deferred objects to enable asynchronous functionality.


Having Tech or Coding Interview? Check 👉 61 AngularJS Interview Questions
Source: codementor.io

Q18: 
What is IIFEs (Immediately Invoked Function Expressions)?

Answer

It’s an Immediately-Invoked Function Expression, or IIFE for short. It executes immediately after it’s created:

(function IIFE(){
	console.log( "Hello!" );
})();
// "Hello!"

This pattern is often used when trying to avoid polluting the global namespace, because all the variables used inside the IIFE (like in any other normal function) are not visible outside its scope.


Having Tech or Coding Interview? Check 👉 179 JavaScript Interview Questions

Q19: 
What is the role of ng-app, ng-init and ng-model directives?

Answer

The main role of these directives is explained as:

  • ng-app - Initialize the angular app.
  • ng-init - Initialize the angular app data.
  • ng-model - Bind the html elem

Having Tech or Coding Interview? Check 👉 61 AngularJS Interview Questions

Q20: 
Why is extending built-in JavaScript objects not a good idea?

Answer

Extending a built-in/native JavaScript object means adding properties/functions to its prototype. While this may seem like a good idea at first, it is dangerous in practice. Imagine your code uses a few libraries that both extend the Array.prototype by adding the same contains method, the implementations will overwrite each other and your code will break if the behavior of these two methods is not the same.

The only time you may want to extend a native object is when you want to create a polyfill, essentially providing your own implementation for a method that is part of the JavaScript specification but might not exist in the user's browser due to it being an older browser.


Having Tech or Coding Interview? Check 👉 179 JavaScript Interview Questions

Q21: 
What is $scope and $rootScope?

Answer
Join FullStack.Cafe to open this Answer. It's Free!
Sign in with GoogleSign in with Google. Opens in new tab
Join 120k+ Developer Who Trust FullStack.Cafe

Q22: 
Explain how $scope.$apply() works?

Answer
Join FullStack.Cafe to open this Answer. It's Free!
Sign in with GoogleSign in with Google. Opens in new tab
Join 120k+ Developer Who Trust FullStack.Cafe
🤖 Having Machine Learning & DS Interview? Check  MLStack.Cafe - 1704 Data Science & ML Interview Questions & Answers!Having ML & DS Interview? Check 🤖 MLStack.Cafe - 1704 ML & DS Interview Questions and Answers

Q23: 
Explain what is injector?

Answer
Join FullStack.Cafe to open this Answer. It's Free!
Sign in with GoogleSign in with Google. Opens in new tab
Join 120k+ Developer Who Trust FullStack.Cafe

Q24: 
How AngularJS is compiled?

Answer
Join FullStack.Cafe to open this Answer. It's Free!
Sign in with GoogleSign in with Google. Opens in new tab
Join 120k+ Developer Who Trust FullStack.Cafe

Q25: 
What is DDO (Directive Definition Object)?

Answer
Join FullStack.Cafe to open this Answer. It's Free!
Sign in with GoogleSign in with Google. Opens in new tab
Join 120k+ Developer Who Trust FullStack.Cafe

Q26: 
What is the difference between $scope and scope?

Answer
Join FullStack.Cafe to open this Answer. It's Free!
Sign in with GoogleSign in with Google. Opens in new tab
Join 120k+ Developer Who Trust FullStack.Cafe

Q27: 
What makes the angular.copy() method so powerful?

Answer
Join FullStack.Cafe to open this Answer. It's Free!
Sign in with GoogleSign in with Google. Opens in new tab
Join 120k+ Developer Who Trust FullStack.Cafe

Q28: 
How AngularJS compilation is different from other JavaScript frameworks?

Answer
Unlock FullStack.Cafe to open all answers and get your next figure job offer!
Share this blog post to open Expert question!

Q29: 
What are Compile, Pre and Post linking in AngularJS?

Answer
Unlock FullStack.Cafe to open all answers and get your next figure job offer!
Share this blog post to open Expert question!
🤖 Having Machine Learning & DS Interview? Check  MLStack.Cafe - 1704 Data Science & ML Interview Questions & Answers!Having ML & DS Interview? Check 🤖 MLStack.Cafe - 1704 ML & DS Interview Questions and Answers
 

Rust has been Stack Overflow’s most loved language for four years in a row and emerged as a compelling language choice for both backend and system developers, offering a unique combination of memory safety, performance, concurrency without Data races...

Clean Architecture provides a clear and modular structure for building software systems, separating business rules from implementation details. It promotes maintainability by allowing for easier updates and changes to specific components without affe...

Azure Service Bus is a crucial component for Azure cloud developers as it provides reliable and scalable messaging capabilities. It enables decoupled communication between different components of a distributed system, promoting flexibility and resili...

Cosmos DB has gained popularity among developers and organizations across various industries, including finance, e-commerce, gaming, IoT, and more. Follow along and learn the 24 most common and advanced Azure Cosmos DB interview questions and answers...
More than any other NoSQL database, and dramatically more than any relational database, MongoDB's document-oriented data model makes it exceptionally easy to add or change fields, among other things. It unlocks Iteration on the project. Iteration f...
Unit Tests and Test Driven Development (TDD) help you really understand the design of the code you are working on. Instead of writing code to do something, you are starting by outlining all the conditions you are subjecting the code to and what outpu...
Domain-Driven Design is nothing magical but it is crucial to understand the importance of Ubiquitous Language, Domain Modeling, Context Mapping, extracting the Bounded Contexts correctly, designing efficient Aggregates and etc. before your next DDD p...
At its core, Microsoft Azure is a public cloud computing platform - with solutions including Infrastructure as a Service (IaaS), Platform as a Service (PaaS), and Software as a Service (SaaS) that can be used for services such as analytics, virtual c...
As an asynchronous event-driven JavaScript runtime, Node.js is designed to build scalable network applications. Follow along to refresh your knowledge and explore the 52 most frequently asked and advanced Node JS Interview Questions and Answers every...
Dependency Injection is most useful when you're aiming for code reuse, versatility and robustness to changes in your problem domain. DI is also useful for decoupling your system. DI also allows easier unit testing without having to hit a database and...