Year: 2020
-
Working with objects in a JavaScript Arrow Function
The JavaScript Arrow function is a shorter way of writing a function expression. Let us say you have a function expression as below, var add = function (num1, num2) { return num1 + num2; } The above function can refactor for a shorter syntax using the arrow function as below, var add = (num1, num2) => num1 + num2; So, as you see, the arrow function provides a convenient and short syntax…
-
Why use new.target inside a function in JavaScript – Simplified
There are four invocation patterns in JavaScript, which means you can call a function in four possible ways. They are, Function Invocation Pattern Constructor Invocation Pattern Method Invocation Pattern Indirect Invocation Pattern Essentially, these four-invocation patterns determine the value of ‘this’ object inside a function. Let us consider the function created below, function add(num1, num2) { console.log(this); // global object }…
-
Got Microsoft Most Valuable Professional Award 11th times
I am very humbled, happy, and excited to share that I have received the prestigious Microsoft Most Valuable Professional Award for the year 2020. This is my 11th MVP award in a row. I thank each one of you for reading my articles, attending my webinars, watching my videos, and participating in ng-India. These awards…
-
Video – Remove Duplicate items from a JavaScript array
This video explains simplest way to remove duplicate items from a JavaScript array. Video shows to use, filter method Set object
-
How to use for…of loop with an Object in JavaScript
In my last post, I discussed Always Use the for…of loop to iterate in JavaScript. After this post, I got a question that, is it possible to use for…of loop with an object? Means, can you use the for…of loop to iterates properties of an object. Let us try this, let Product = { Id: 1, Title: 'Pen', Price: 1000, sendDetail: () => { }…
-
Always Use the for…of loop to iterate in JavaScript
In JavaScript to iterate over the values of an array, map, object, etc. use the for…of loop. In a specified order, it iterates over the set of values of an iterable object such that array. It would be best if you use a for…of loop for looping. You must have used the for…in loop to…
-
The simplest way to Remove Duplicate Items from a JavaScript Array
You may have often come across a requirement to remove duplicate items from a JavaScript array. There are multiple ways to achieve it. Such that, Using the forEach loop and manually checking for the duplicate values Using the array’s filter method and others Using the Set object Let us say; you have an array as…
-
How to use conditions in Angular Template using
There are various ways you can apply conditions on Angular Template. Usually, you apply conditions to show a particular value or render a specific element based on a condition. In this post, let us see, the simplest way of achieving the conditions in Angular Template using the <ng-container> and <ng-template>. To start with consider data,…
-
Using Spread Syntax to Merge Objects in JavaScript
Have you come across a requirement to merge two or more object in another object? Most simply, you can achieve it by using JavaScript Spread syntax (…). Due to its multi functionalities purpose, JavaScript Spread Syntax is one of the most useful operators. You can use it, Rest parameters to a function To merge two…
-
Why use exportAs Property in Angular
Have you used exportAs property of a directive? It could be instrumental in working with public methods of a directive. Let us say; you have created a custom directive to change the background colour of the host element on the mouse hover as below, The above custom directive changes the background colour of the host…