Angular interview questions – part 1

1 What is typescript? It is a strict syntactical superset of JavaScript, and adds optionaltype-checking along with the latest ECMAScript features. 2 What is two way data binding in angular? Two-way Binding. Data binding in AngularJS is the synchronization between the model and the view. When data in the model changes, the view reflects the change, and when data in the view changes, the model is updated as well. Binding   3 Types of bindings in angular ? 1 Interpolation -eg- <h1>{{}}</h1> //interpolation is in braces 2 Two way binding – <input [(ngModel)]=””/> 3 One way binding – <h1 [innerText]=””></h1> //Bindings like inner text 4 Event Binding – <button ng-click=”userData()”>Send</h1> //Binding events like click   4 What are authGuards? With AuthGuards/RouterGuards we can prevent users from accessing areas that they’re not allowed to access.Or prevent navigating away. There are four kinds of guards.You have to import it from the @angular/router module CanActivate Checks to see if a user can visit a route. CanActivateChild Checks to see if a user can visit a routes children. CanDeactivate Checks to see if a user can exit a route. Resolve Performs route data retrieval before route activation. CanLoad Checks to see if a user can…

Top 10 Javascript interview questions : Concepts every javascript developer should know
interview questions , Javascript / August 20, 2018

1  Explain let,var and const variable declaration and explain their scope .what is strict mode? 2  What are callbacks and callback hell in javascript . What are higher order functions? 3 What is  hositing in javascript ? 4 What are prototypes and explain Prototypal inhertiance ? 5 What are Closures in javascript? 6 What are arrow functions / fat arrow functions  in Javascript? 7 What doe this keyword indicate in javascript? 8 What are promises in JavaScript? 9 What is bubbling and propogation in Javascript? 10 What are generators in Javascript? ANSWERS 1  The scope of var is the current execution context.That is, scope of var is global,if used outside a function and the scope is the function block if used inside the function. See more here  Understanding variable scope(let,var,const),hoisting in Javascript and Temporal Dead Zone(TDZ) 2  In  most programming languages , functions can accept other function(s) as arguments or return a function .Such functions are called Higher order functions.In JavaScript most APIs and Modules can accept function as an argument to a function .The functions are called  callbacks.see more here Understanding Callbacks and Callback hell in JavaScript : asynchronous behaviour of Javascript Part -1 3 To hoist means to pull or move up . Javascript hoisting means variable and function declarations are pulled to the top of the scope while…

How to accurately check date range to prevent overlapping:mysql
Snippets , Requests / July 29, 2018

Q:I have a table with events , and each event has an auditorium id,start_date and end_date.In need to insert a new event in to the table without any overlapping on date range in an auditorium   select IF(count(*)>0, true, false) from events where ‘YOUR_START_DATE‘ <= end_date and ‘YOUR_END_DATE‘ >= start_date; OR select IF(count(*)>0, true, false) from events where ‘YOUR_START_DATE‘  BETWEEN start_date AND end_date or ‘YOUR_END_DATE‘ BETWEEN start_date and end_date and end_date or (‘YOUR_START_DATE‘ < start_date and ‘YOUR_END_DATE‘ > end_date); If true do not proceed with insert if false continue


Creating a Cron job in Laravel 5.2 :Task Scheduling
PHP , Beginner , Snippets / July 23, 2018

To create a cron job in Laravel 5.2 ,move to the app/console/ folder.The console folder contains all the relevant configuration files and folders for you to create a custom artisan command in Laravel 5.6 .  After creating the custom artisan command ,we can schedule the command to be run in specific intervals Step 1 Run

  to create new custom artisan command,This will generate a class called app/Console/Commands/CronJob.php.The newly generated file will have the following structure.You have to fill in name and description variables in the file.You can use the DB and MODEL files from CronJob.php. The file extends the Command Class   app/Console/Commands/CronJob.php

Here we select a set of users based on some custom criteria from the users table and do something to them periodically with the cron job.The action for the should be written in the CronJob.php – handle() function.The class defines our command.To run this need to use the following php artisan cronjob Step 2 Scheduling the job To schedule the when to run the command we have created open the kernel.php file in the app/console/ folder app/console/kernel.php

The kernel class extends ConsoleKernel .To add the commands

and to schedule the command

  This runs…

Understanding Callbacks and Callback hell in JavaScript : asynchronous behaviour of Javascript Part -1

In most programming languages, functions can accept other function(s) as arguments or return a function. Such functions are called Higher-order functions. In JavaScript, most APIs and Modules can accept a function as an argument to a function. The functions are called callbacks. Structure of callbacks

Note that JavaScript functions behave as objects. We can set a function as an object property or store a function into a variable. JavaScript is a non-blocking programming language. It doesn’t wait or block operation to finish but keeps on executing. For example, consider the case when data is fetched asynchronously, then javascript doesn’t wait for the asynchronous call to get data but keeps executing the next line of code. So in order to do something with the data, we can use callbacks. See the below example in which we use a timeout to wait for the data just like an XHR request which may take some time to complete

Asynchronous callback with  Jquery and a callback function

  CALLBACK HELL Consider the above example in which we use a callback function which is passed as an argument to the $.get function in Jquery. Now what happens when we want to send subsequent requests is that…

Implementing priority queue in PHP
PHP , programming concepts / June 2, 2018

Queue is a First In First Out(FIFO) Data Structure.In a priority queue, an element with high priority is served before an element with low priority.The Standard PHP Library has the SplPriorityQueue class which can be used to implement priority queue.The insert(‘item’,priority) method is used to insert item and the corresponding priority in to the queue.See the below example to see mail sending to different mail id’s that have different priorities.You can use while to iterate thorough the queue and process each one or the results. SplPriorityQueue A priority queue can be implemented using many of the data structures that we’ve already studied (array, inked list, binary search tree). However, those data structures do not provide the most efficient operations. To make all of the operations  efficient, heap can be used . SplPriorityQueue is implemented using Max Heap


Array reduce functions in Javascript
Javascript / June 1, 2018

The reduce() method applies a function against an accumulator and each element in the array (from left to right) to reduce it to a single value.Reduce function makes it to a single value.

Here we can see reduce always accepts a call back function. The variable a  is called the accumulator in which the return value is stored The variable b represents each variable inside the array.Thus what reduce does is that it runs a function on each values inside the array. The return value of the function is stored in an accumulator (result/total). Now we take a look at how to calculate the sum of squares of all the values present inside the array.So that you get a better understanding of what happens inside the reduce function.This time we define the function seperately.

  The above returns sum of squares of all values inside the array.

Array map functions in Javascript
Javascript / June 1, 2018

Conside a Javascrpt Array of numbers.We need to make an array which contains squares of all these numbers.What we can do to achieve this is using a for loop.

For doing these Javascript has another function called MAP function on array.Using the map function the above result can be achieved in the following way

Array Map on Array of objects in Javascript


js/nodejs/angularjs/ts interview questions
interview questions / May 31, 2018

1  What is data binding in angularjs Data binding in AngularJS is the synchronization between the model and the view.                                      2  What are the key features of angularjs    Modules.    Directives.    Expressions.    Controller.    Scope.    Data Binding.    Validations.    Filters.    Services.  Routing.  Dependency Injection.  Testing. 3  What are directives AngularJS extends HTML attributes with directives 4  What are controllers Controllers are functions which provide data and logic to the HTML page we are going to visualize the data. 5  What do you mean by compile and link in angularjs To have a complete understanding of angularjs understanding the angular is lifecycle is necessary .Angularjs lifecycle        has three phases. Bootstrap phase- The bootstrap phase is the phase in which the library is loaded,module is created based on your ng-app and any                dependencies to your module is loaded Compilation phase- The  compilation phase is the phase which include two steps Traversing the  DOM and collecting all the directives and        then linking the directives to the…

Understanding ‘this’ in Javascript
interview questions , Javascript / March 20, 2018

This in Javascript refers to the object to which the function belongs. The value of this is determined by how a function is called.’This’ refers to the “owner” of the function.In the case of a normal function like below ‘this‘ refers to the global object (window object)

In the above example, a function WrapAll() is being called from the global scope. The global scope means in the context of window object this and ‘use strict’

Here this is undefined as use strict prevent global object   Now we can see how the this keyword works in an objects point of view by creating a new object.To create an object,we need a constructor function

Callback functions In the above object we use fetch which returns a promise.To the promise .then we give a call back function  as seen below

Here , we can see that the console.log inside the callback function gives the window object.This is because the callback function is a normal function in Javascript which is put in to the callstack by the event loop from the event queue.   To get the ‘this’ inside the callback we can use bind()

We can also use…

Share this page in social media platforms