Javascript Tips : 1 → Using Closure functionality to create a function that sets the style to…

The styleSetter function will return a function that has a local reference to the element that we have passed to styleSetter function so this is stored in the scope of the function which is returned by the function styleSetter . Follow Javascript Jeep🚙 🥶.

Learn TypeScript:Part 2 → Type declaration.

Learn basic features of typescript Create a new file with extenstion .ts ,say add.ts In that file we will create a variable a , then assign different types of values then see what typescript says When we compile the code using tsc add.ts . It generates a.js file in the same folder . And it doesn’t reports any error. So …

Learn TypeScript . Part 1.

First part in learning TypeScript. What is TypeScript ? TypeScript is modern JavaScript + types . TypeScript is an open-source programming language developed and maintained by Microsoft. Typically Typescript is Javascript with types. So that the type error and some of data type related bugs can be resolved . It is highly useful in large projects. Why TypeScript? …

Getting a random item from an array

Let’s write a function to return a random element from an array. We can use Math.random() to generate a number between 0–1(inclusive of 0, but not 1) randomly. Then multiply the random number with the length of the array. floor to result to make it whole number . That’s it we find the random Index. Let’s …

Implement copy-on-click using JavaScript

We have seen many websites have the option to copy a block of text by clicking a button. Let’s learn how to build this using vanilla JavaScript. Steps to copy text in javascript 1. Create a textarea element 2. Get the text from the div using div.innerText 3. Set the value of textarea with the …

Find the number of days between two dates in Javascript

Learn to find the difference between two dates in javascript. Let’s take an example of what we are going to do. We have a function that takes two dates as the input, and it returns the number of days. If we pass May 22, 2019 and May 28, 2019, then it returns 7. The solution …

Different ways to create Date in JavaScript.

Learn about Date object in JavaScript To get the current time and date create a Date object without any arguments. var now = new Date(); log(now) // Tue Mar 12 2019 21:14:43 GMT+0530 (India Standard Time) There are many ways of creating a Date object Passing milliseconds as arguments If there is single argument and …

Javascript Equivalent method for jQuery addClass method.

The jQuery addClass method will add the class provided to the element or elements. Consider that we have an “div” element stored in the variable “divElement” . <div id = “divElement”> </div> <script> let divElement = document.getElementById(‘divElement’)</script> now we can add class to the “divElement” in JavaScript by function addClass(element, className) { divElement.classList += ” className”; …

Understand filter in javascript.

Javascript filter method. filter() is used to filter the array and creates a new array with the elements which satisfy the condition provided as predicate function . filter method takes a predicate( predicate is commonly understood to be a Boolean-valued function P: X→ {true, false}) as argument , to test each element of the array satisfy condition …

Get keys of the object in javascript

Object.keys() method can be used to get the keys of the object. We get the keys in same order as we get in the normal for..in loop It returns an array filled with the keys of the object. // array var num = [1 , 2, 3];console.log(Object.keys(num)); // [‘0’, ‘1’, ‘2’] // objectvar obj = …

Design a site like this with WordPress.com
Get started