How to an make object immutable in Javascript with examples

In this section, we will look at how to make an object immutable in Javascript. We will first look at the freeze() method and later discuss the seal() method and how they help make an object immutable. Before looking at how to make an object immutable in Javascript, first, let us understand what mutable and immutable objects are. In mutable objects, we can change the state of the object. Whereas, in immutable objects, we are not allowed to change the state of the object....

July 2, 2022 · 4 min

Understanding Javascript objects with examples

Javascript objects are entities that contain properties. They are basically collections of name-value pairs and methods. const object = { key1: value1, key2: value2, key3: function() {...} } In Javascript, almost everything is an object except the primitive data types are objects. The list of primitive types in Javascript are: number string boolean symbol undefined null Creating Javascript Objects They are two ways of creating Javascript objects, one is using the object literal and the other is using the constructor....

June 30, 2022 · 2 min

Understanding 'this' in Javascript with examples

The this keyword in Javascript is an essential concept, and many developers sometimes find it hard to understand. The value this can depend on many factors. And what makes it more confusing is that its value is determined at the runtime. In this section, we will go through the concept of this keyword in-depth and try to make sense of how it works in Javascript. Global scope Before we get into the complexity of the this keyword, let’s first see what it returns when used in a global scope....

June 24, 2022 · 6 min

4 ways of invoking a function in Javascript with Examples

There are 4 ways of invoking a function in Javascript. As a Function As a Method As a Constructor call() and apply() In this section, we will look at each of them in detail with examples. Calling function as a function Let us first look at calling a function as a normal function. This is fairly straightforward. function greet() { console.log("Hello"); } greet(); // Hello We have a function greet() which logs the message ”Hello” on the browser console....

June 23, 2022 · 4 min

Understanding First Class Functions in Javascript with Examples

Introduction In this section, we will look at what is meant by “First Class Functions” in Javascript, how to define and use them with examples. What are First Class Functions? Let us begin by understanding what is a first class function? In simple terms, First class functions are functions that can be treated as variables i.e, functions can be assigned as value to a variable or it can be passed as an argument to another function or even can be returned by another function just like any other variable in Javascript....

June 21, 2022 · 3 min

Creating an array using Array.of() in Javascript (with examples)

Create a new array instance using Array.of() Method In this section we will look at how to create an array using the Array.of() method and how it differs from the Array constructor. Array.of() method is used for creating a new instance of an array. It takes as an argument one or more elements. The elements can be of different types. Before looking at Array.of method, let us first look at creating an array using the constructor....

June 21, 2022 · 2 min

How to get input value in Vue(with examples)

If you are just getting started with Vue, one of the common questions that you will find yourself asking is how to get the value of the input field? In this article, we will look at how easy it is to obtain input value in Vue. Using v-model directive The v-model directive in Vue creates a two-way binding on the input element. All you need to do is simply declare a v-model directive for the input element and reference it to get the value....

August 7, 2020 · 4 min

Using v-for directive in Vue (with examples)

The v-for directive in Vue is used for looping over an array or object. In this article, we will take a close look at the v-for directive with examples. v-for loop x number of times(number range) We will start with a simple example of looping ‘x’ number of times using the v-for directive. In this example, we will loop from 1 to 10 and display each number using the list....

July 31, 2020 · 4 min

Create and Run your First Vue.js App using CDN

Introduction Over the last two decades the front end development as changed considerably. Websites now are more interactive with a lot of dynamic behaviour. This also means a lot of work for the developers to keep up with the trend. Fortunately, there are many javascript frameworks that can help you build interactive applications. One such framework is Vue.js, a powerful framework to create the modern-day user interface. It is fast, reliable, developer-friendly and easy to start with....

July 18, 2020 · 4 min

Vuejs v-if, v-Else conditional directives | with Examples

Table of Contents Introduction v-if v-else Using v-if on template v-else-if Multiple conditions Difference between v-if and v-show v-if v-else Choosing between v-if and v-show Introduction To conditionally render the block, Vue uses the v-if directive. In this article, we will look at how to use v-if directive in Vue with examples. v-if <span v-if="true">Hey there!</span> If the expression assigned to v-if returns a truthy value, the block gets rendered in DOM....

July 18, 2020 · 3 min