- 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 9289 Articles for Object Oriented Programming
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
170 Views
Following is the code for using named arguments in JavaScript functions −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .sample, .result { font-size: 18px; font-weight: 500; color: red; } .result { color: rebeccapurple; } Named arguments in JavaScript functions CLICK HERE Click on the above button to call a function and pass above object to it as argument let sampleEle ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
338 Views
Following is the code to increment or decrement a variable on keyboard up/down press in JavaScript −Example Live Demo >Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result { font-size: 20px; font-weight: 500; } Changing variable value on keyboad up/down keypress { if (event.keyCode === 38) { resEle.innerHTML = ++a; } else if (event.keyCode === 40) { resEle.innerHTML = --a; } }); OutputThe above code will produce the following output −On pressing up arrow key a couple of times −On pressing down arrow key a few times −
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
20K+ Views
The JavaScript switch statement can contain return statements if it is present inside a function. The function will return the value in the switch statement and the code after the switch statement will not be executed.Following is the code to have return statements in JavaScript switch statement −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result { font-size: 20px; font-weight: 500; } Return statement in JavaScript switch Enter day 1-7 CHECK ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
2K+ Views
Following is the code to group array of objects by id 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; } group the array of objects by Id in JavaScript { name: 'Rohan', age: 18 }, { name: 'Mohan', age: 20 }, { name: 'Shawn', age: 18 }, { name: 'Michael', age: 18 }, { name: 'David', age: 20 } ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
3K+ Views
Following is the code for disabling mouse event on certain elements using JavaScript −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result { font-size: 18px; font-weight: 500; color: rebeccapurple; } .size { font-size: 30px; } Disable Mouse events using JavaScript This is some text inside a div DISABLE ENABLE Click on the above button to enable or disable mouse events let resEle ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
359 Views
Following is the code to access browsing history 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; } Program to access browsing history CLICK HERE Click on the above button to see history length FORWARD BACKWARD Click on the above button to go forward or backward let resEle = document.querySelector(".result"); let BtnEle = document.querySelectorAll(".Btn"); BtnEle[0].addEventListener("click", () => ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
92 Views
JavaScript doesn’t support Enums out of the box. The only way to have enums in javaScript is to implement them using objects.Following is the code showing enumerated types 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; } Enumerated Types in JavaScript CLICK HERE Click on the above button to get the color values let resEle = document.querySelector(".result"); ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
415 Views
Following is the code to embed JavaScript in html file −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result { font-size: 18px; font-weight: 500; color: rebeccapurple; } Embed javascript in html file let resEle = document.querySelector(".result"); resEle.innerHTML += "Inline javaScript loaded" + ""; script.jsresEle.innerHTML += 'External JavaScript loaded ';OutputThe above code will produce the following output −
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
1K+ Views
The arrow functions also known as shorthand functions were introduced in ES2015 and allows us to write function in a shorter way. They don’t have their own binding to this and get the this from the surrounding context.Following is the code showing shorthand functions 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; } Shorthand function in JavaScript CLICK HERE Click ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
412 Views
Following is the code to create a URL object using JavaScript −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result { font-size: 18px; font-weight: 500; color: rebeccapurple; } Url object in JavaScript CLICK HERE Click on the above button to create and display a url object let resEle = document.querySelector(".result"); let url = new URL("https://google.com/image=23&size=440px"); document.querySelector(".Btn").addEventListener("click", () => { resEle.innerHTML += "url protocol = " + url.protocol + ""; resEle.innerHTML += "url host = " + url.host + ""; resEle.innerHTML += "url.pathname = " + url.pathname + ""; }); OutputThe above code will produce the following output −On clicking the ‘CLICK HERE’ button −