- 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 9297 Articles for Object Oriented Programming
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
954 Views
Following is the code to create a unique ID for each object −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result { font-size: 18px; font-weight: 500; color: rebeccapurple; } Create a unique ID for each object CLICK HERE { if (obj.id === obj1.id) { resEle.innerHTML = "The id generated are not unique "; } else { resEle.innerHTML = "The id generated is unique for each object"; } }); 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)
2K+ Views
Following is the code to draw a circle in JavaScript −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .circleCanvas { border: 3px solid #110101; } Draw a circle in JavaScript CLICK HERE Click on the above button to create a circle in the above canvas element let canvasEle = document.querySelector(".circleCanvas"); let BtnEle = document.querySelector(".Btn"); BtnEle.addEventListener("click", () => { var circle = canvasEle.getContext("2d"); circle.beginPath(); circle.arc(180, 100, 90, 0, 2 * Math.PI); circle.stroke(); }); 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)
528 Views
Following is the code for single and multidimentsional array 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; } Single dimensional array vs multidimensional array Single dimensional Array Multidimensional Array CLICK HERE Click on the above button to display single and multidimensional array let resEle = document.querySelector(".result"); let ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
370 Views
Following is the code for setting property in an empty object using for loop 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; } Setting property in an empty object using for loop CLICK HERE Click on the above button to populate the empty object obj1 let resEle = document.querySelector(".result"); let BtnEle = document.querySelector(".Btn"); let obj = ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
599 Views
To assign static methods to class in JavaScript simply prefix the method with keyword static. The static methods then can be called without instantiating the class.Following is the code to assign static methods to a class 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; } Assign static methods to a class in JavaScript CLICK HERE Click on the above button ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
85 Views
Following is the code to de-structure an imported 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; } De-structure an imported object in JavaScript CLICK HERE Click on the above button to destructure the person object script.jsimport person from "./sample.js"; let resEle = document.querySelector(".result"); let BtnEle = document.querySelector(".Btn"); let {firstName, lastName, age} = person; BtnEle.addEventListener("click", () => { ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
249 Views
The not a constructor function error occurs if we use an object or a variable as a constructor that isn’t a constructor.Following is the code for not a constructor function error 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; } Not a constructor function error CLICK HERE Click on the above button to use a variable as constructor ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
366 Views
Following is the code to group objects based on a value 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 objects based on a value in JavaScript { name: 'Rohan', age: 18 }, { name: 'Mohan', age: 20 }, { name: 'Shawn', age: 18 }, { name: 'Michael', age: 18 }, { name: 'David', age: 20 } CLICK ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
2K+ Views
Following is the code to multiply two arrays 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; } Multiply two Arrays in JavaScript CLICK HERE Click the above button to multiply the above two arrays let BtnEle = document.querySelector(".Btn"); let resEle = document.querySelector(".result"); let sampleEle ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
404 Views
Following is the code to sort JavaScript object by length of array properties −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } Sorting JavaScript object by length of array properties CLICK HERE Click the above button to sort the objects inside arrObj based on Subject array length let BtnEle = document.querySelector(".Btn"); let arrObj = [ { name: "Rohan", Subject: ["Maths", "Science", "EVS", "SST"] }, { name: "Mohan", Subject: ["Maths", "Science", "SST"] }, ... Read More