
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 6710 Articles for Javascript

378 Views
The call(), apply() and bind() are used to borrow methods in JavaScript.Following is the code for borrowing methods in JavaScript −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result, .sample { font-size: 18px; font-weight: 500; color: rebeccapurple; } .result { color: red; } Borrowing a method in JavaScript CLICK HERE Click on the above button to borrow the welcome method of object obj ... Read More

113 Views
Following is the code to transform JavaScript arrays using maps.Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result,.sample { font-size: 18px; font-weight: 500; color: rebeccapurple; } .result { color: red; } Transform JavaScript arrays using maps [22,33,44,55] CLICK HERE Click on the above button to square each element of the above array let resEle = document.querySelector(".result"); let BtnEle = document.querySelector(".Btn"); let arr = [22, 33, 44, 55]; BtnEle.addEventListener("click", () => { resEle.innerHTML = arr.map((a) => a * a); }); OutputThe above code will produce the following output −On clicking the ‘CLICK HERE’ button −

490 Views
What is a Higher Order Function in JavaScript? JavaScript being a multi paradigm language, it supports procedural programming, functional programming and object oriented programming. Since it is also a functional programming language javascript handles functions as a first class entities, where functions can be assigned to a variable, set it as an object's property, and can pass them as an argument to another function. This characteristic in javascript helps in implementing Higher Order Functions, which can operate on other functions either by taking them as an argument or by returning them. Let us take an example and implement it ... Read More

147 Views
Following is the code to de-structure already declared variables 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; } De-structure to already-declared variables CLICK HERE Click on the above button to destructure the personObj object let resEle = document.querySelector(".result"); let BtnEle = document.querySelector(".Btn"); let name, age, personObj; personObj = { name: "Rohan", age: 19, }; BtnEle.addEventListener("click", () => { ({ name, age } = personObj); resEle.innerHTML = " name = " + name + "age = " + age; }); OutputThe above code will produce the following output −On clicking the ‘CLICK HERE’ button −

85 Views
Following is the code to pass an object of parameters to a function −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result, .sample { font-size: 18px; font-weight: 500; color: rebeccapurple; } .sample { color: red; } Passing an object of parameters into a function CLICK HERE Click on the above button to add 4 object values by passing them to a function let ... Read More

267 Views
Following is the code to merge objects into a single object array −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result, .sample { font-size: 18px; font-weight: 500; color: rebeccapurple; } .sample { color: red; } Merge objects into a single object array [{id:22, class:7}, {name:'Rohan', age:12}, {state:'Delhi', country:'India'}] CLICK HERE Click on the above button to merge the above objects inside array into ... Read More

225 Views
The JavaScript alert() function is used to display a popup message to the user.Following is the code for the JavaScript alert() function −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } Javascript text alert CLICK HERE Click on the above button to trigger the alert popup let BtnEle = document.querySelector(".Btn"); BtnEle.addEventListener("click", () => { alert("You pressed the button"); }); OutputThe above code will produce the following output −On clicking the ‘CLICK HERE’ button −

3K+ Views
The image object represents the HTML element.Following is the code for image object 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; } The image() object in JavaScript CLICK HERE Click on the above button to display an image let resEle = document.querySelector(".result"); let BtnEle = document.querySelector(".Btn"); let newImage = new Image(500, 300); newImage.src = "https://i.picsum.photos/id/195/536/354.jpg"; BtnEle.addEventListener("click", () => { resEle.appendChild(newImage); }); OutputThe above code will produce the following output −On clicking the ‘CLICK HERE’ button −

182 Views
Following is the code to apply reduce method to objects in JavaScript −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result, .sample { font-size: 18px; font-weight: 500; color: rebeccapurple; } .result { color: red; } Reduce method for objects in JavaScript { a:6, b:2, c:9, d:5, } CLICK HERE Click on the above button to multiply the above object values together let resEle ... Read More

206 Views
Following is the code to convert two arrays into one JavaScript object −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result, .sample { font-size: 18px; font-weight: 500; color: rebeccapurple; } .result { color: red; } Convert two arrays into one JavaScript object ["firstName", "lastName", "age"]["Rohan", "Sharma", 21] CLICK HERE Click on the above button to create an object from the above two arrays ... Read More