- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 9292 Articles for Object Oriented Programming
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
318 Views
The conscise arrow function syntax is as follows −(param1, param2) =>param1+param2It doesn’t have the function keyword and the function body. There is only => between the parameters and function body and if there is single parameter than it can also be written like this −param1=>param1*2It has implicit return if there aren’t curly braces {} after the =>.Following is the code to implement concise arrow functions in JavaScript −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result { font-size: 20px; ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
237 Views
The fat arrow function syntax looks like the following −(param1, param2, ..)=>{ }It doesn’t have the function keyword and only have the => between the parameters and the function body.Following is the code implementing fat arrow functions 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; } Fat arrow functions CLICK HERE Click on the above button to call the add() fat ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
368 Views
Following is the code for passing parameters to callback functions 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; } Passing parameters to callback functions CLICK HERE Click on the above button to pass parameter to callback function add2 and call it let resEle = document.querySelector(".result"); function add2(a) { return a + 2; } function multiply9(fn, num) { return fn(num) * 9; } document.querySelector(".Btn").addEventListener("click", () => { resEle.innerHTML = "The number returned = " + multiply9(add2, 8); }); OutputOn clicking the ‘CLICK HERE’ button −
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
141 Views
To empty an array in JavaScript, there are four ways −Setting to new Array − In this we set our array variable to a new empty array.Using length property − In this we set the length property of our array to 0.Using pop − In this we continuously pop the array elements till the length reaches to 0.Using splice − In this we put the start index as 0 and the no of elements to removed as array.length-1.Following is the code to display no. of ways to empty an array in JavaScript −Example Live Demo Document ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
118 Views
Following is the code to implement asynchronous loop 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; } Asynchronous loop in JavaScript CLICK HERE Click on the above button to start our asynchronous loop let resEle = document.querySelector(".result"); async function waitTime(time) { return new Promise((resolve) => { setTimeout(resolve, time); }); } async function someFunction() { for (let i = 0; i < 10; i++) { await waitTime(2000); resEle.innerHTML += "i = " + i + ""; } } document.querySelector(".Btn").addEventListener("click", () => { someFunction(); }); OutputOn clicking the ‘CLICK HERE’ button the loop will print 1 to 10 −
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
98 Views
The best way to add an event to any element is to use the addEventListener() method.Following is the code to add an event in JavaScript −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result{ font-size: 20px; font-weight: 500; color: rebeccapurple; } Adding event in JavaScript CLICK HERE Click on the above button to increment the font size of above text let resEle = document.querySelector(".result"); document.querySelector(".Btn").addEventListener("click", () => { resEle.style.fontSize = "34px"; }); OutputThe above code will produce the following output −On clicking the ‘CLICK HERE’ button −
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
174 Views
Following is the code to decrement a date by 1 day 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: rebeccapurple; } JavaScript program to decrement a date by 1 day Decrement Click on the above button to decrement the date by one day let resEle = document.querySelector(".result"); let sampleEle = document.querySelector(".sample"); let date = new Date(); sampleEle.innerHTML = date; document.querySelector(".Btn").addEventListener("click", () => { date.setDate(date.getDate() - 1); resEle.innerHTML = "New Date = " + date; }); OutputThe above code will produce the following output −On clicking the ‘Decrement’ button −
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
348 Views
Following is the code for finding keys of a hash in JavaScript −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result { font-size: 20px; font-weight: 500; } Find keys of a hash in JavaScript DISPLAY Click on the above button to display the hash keys let resEle = document.querySelector(".result"); let obj = { firstName: "Rohan", lastName: "Sharma", age: 22, }; document.querySelector(".Btn").addEventListener("click", () => { resEle.innerHTML += "object keys are " + Object.keys(obj); }); OutputThe above code will produce the following output −On clicking the ‘DISPLAY’ button −
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
296 Views
Following is the code to to display name to be only numbers, letters and underscore using regex in JavaScript −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result { font-size: 20px; font-weight: 500; } , letters and underscore only regex match
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
426 Views
Following is the code to validate decimal numbers in JavaScript −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result { font-size: 20px; font-weight: 500; } Validate decimal numbers in JavaScript CHECK Click the above button to check if a valid decimal number is entered or not let resEle = document.querySelector(".result"); document.querySelector(".Btn").addEventListener("click", () => { var str = document.querySelector(".num").value; var regex = /^[-+]?[0-9]+\.[0-9]+$/; ... Read More