Found 6710 Articles for Javascript

How to add properties and methods to an existing object in JavaScript?

AmitDiwan
Updated on 22-Jul-2020 08:04:08

257 Views

Following is the code for adding properties and methods to an existing object in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 20px;       font-weight: 500;       color: blueviolet;    } Add properties and methods to an existing object in JavaScript CLICK HERE Click on the above button to add property and methods to student object and display them    let resEle = document.querySelector(".result");    let BtnEle = ... Read More

Currying VS Partial Application in JavaScript.

AmitDiwan
Updated on 22-Jul-2020 08:02:59

272 Views

Currying − In currying a function takes another function and some arguments. The function then returns one function with one parameter only. It returns the function with one argument which can be chained together.Partial application − In partial application some of the arguments can be bind to some values to produce a function with less arguments.Following is the code for currying vs partial application in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 18px;       ... Read More

Drawing an image in canvas using in JavaScript

AmitDiwan
Updated on 22-Jul-2020 07:58:39

464 Views

Following is the code for drawing an image in canvas using JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    } Drawing an image in canvas CLICK HERE Click on the above button to draw the image in canvas    let resEle = document.querySelector(".result");    let BtnEle = document.querySelector(".Btn");    BtnEle.addEventListener("click", () => {       var c = document.querySelector(".canvas1");       var ctx = c.getContext("2d");       var img = document.querySelector(".flower");       ctx.drawImage(img, 10, 10);    }); OutputOn clicking the ‘CLICK HERE’ button −

JavaScript program to convert 24 hours format to 12 hours

Ravi Ranjan
Updated on 06-Jun-2025 19:13:26

2K+ Views

To convert 24 hours format to 12 hours in Javascript, we have discussed two different approaches. In this article we are having time in 24 hours format, our task is to write a JavaScript program to convert 24 hours format to 12 hours. Approaches to Convert 24-hours format to 12-hours Here is a list of approaches to write a JavaScript program to convert 24 hours format to 12 hours which we will be discussing in this article with stepwise explanation and complete example codes. Using if-else Statement Using Date Object ... Read More

First class function in JavaScript

AmitDiwan
Updated on 22-Jul-2020 07:53:06

667 Views

JavaScript treats functions as objects and allow us to pass functions as parameter to another function and even return functions from other functions. In JavaScript the functions are first class functions meaning we can store them in variable, objects and array. The higher order functions can take function, return them or do both.Following is the code to implement first class functions in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result,    .sample {       font-size: 18px;       font-weight: ... Read More

Identifying False values in JavaScript

AmitDiwan
Updated on 22-Jul-2020 07:51:36

527 Views

JavaScript has the following values evaluate to false when evaluated as Boolean type − false0empty string: "" , '' , or ``nullundefinedNaN — not a number valueFollowing is the code for identifying falsy values in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result{       font-size: 20px;       font-weight: 500;       color: blueviolet;    } Identifying Falsy values in JavaScript. CLICK HERE Click on the above button to identify some of the ... Read More

Implementing Linear Search in JavaScript

AmitDiwan
Updated on 22-Jul-2020 07:48:36

437 Views

Following is the code for implementing linear search in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result,.sample {       font-size: 20px;       font-weight: 500;       color: blueviolet;    }    .sample{       color:red;    } Implementing linear search [1,19,5,11,22,55] CLICK HERE Click on the above button to search for 22 in the above array    let resEle = document.querySelector(".result");    let BtnEle = document.querySelector(".Btn");    let arr = [1,19,5,11,22,55];    BtnEle.addEventListener("click", () => {       for(let i=0;i

ES6 Property Shorthands in JavaScript

AmitDiwan
Updated on 22-Jul-2020 07:47:39

183 Views

In ES6, if the object key name and variables passed as properties value have same name then we can simply omit the value name and only specify the key name.Following is the code for property shorthands in JavaScript −Example Live Demo Document body {     font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 20px;       font-weight: 500;       color: blueviolet;    } ES6 Property Shorthands in JavaScript CLICK HERE Click on the above ... Read More

Awaiting on dynamic imports in JavaScript.

AmitDiwan
Updated on 22-Jul-2020 07:42:30

173 Views

Note − You will need a localhost server to run this example −Following is the code for dynamic imports in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 18px;       font-weight: 500;       color: rebeccapurple;    } Awaiting on dynamic imports in JavaScript CLICK HERE Click on the above button to dynamically import modules    document.querySelector(".Btn").addEventListener("click", loadModule);    let resEle = document.querySelector(".result");    async function loadModule() {   ... Read More

Nesting template strings in JavaScript

AmitDiwan
Updated on 22-Jul-2020 07:40:39

587 Views

Following is the code for nesting template strings in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 20px;       font-weight: 500;       color: blueviolet;    } Nesting template strings in JavaScript CLICK HERE Click on the above button to display the fullName using nested template string    let resEle = document.querySelector(".result");    let BtnEle = document.querySelector(".Btn");    function fullName(fName, lName) {       return fName + " " + lName;    }    let firstName = "Rohan";    let lastName = "Sharma";    BtnEle.addEventListener("click", () => {       resEle.innerHTML = `FirstName = ${firstName} and lastname = ${lastName} and       fullname = ${fullName(          `${firstName}`,          `${lastName}`       )}`;    }); OutputOn clicking the ‘CLICK HERE’ button −

Advertisements