- 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 9315 Articles for Object Oriented Programming
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
176 Views
Let’s say we are getting two values with prompt −var firstvalue = parseInt(prompt("Enter the value1")); var secondvalue = parseInt(prompt("Enter the value2"));ExampleFollowing is the code − Live Demo Document var firstvalue = parseInt(prompt("Enter the value1")); var secondvalue = parseInt(prompt("Enter the value2")); if (firstvalue * secondvalue > 50) document.write("Result is correct"); else document.write("Result is not correct"); To run the above program, save the file name anyName.html (index.html). Right click on the file and select the option “Open ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
892 Views
To find specific words in an array, you can use includes(). We have the following array −var sentence = ["My Name is John Smith. My Favourite Subject is JavaScript. I live in US. I like Hockey"];Now, the following is an array having the words we need to search in the above “sentence” array −var keywords = ["John", "AUS", "JavaScript", "Hockey"];ExampleFollowing is the code −var keywords = ["John", "AUS", "JavaScript", "Hockey"]; var sentence = ["My Name is John Smith. My Favourite Subject is JavaScript. I live in US. I like Hockey"]; const matched = []; for (var index = 0; index ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
73 Views
You cannot change the value of an object when it is defined using const keyword.After changing it will remain same.Let’s say the following is our variable defined with const −const details1 = { firstName: 'David', subjectDetails: { subjectName: 'JavaScript' } }ExampleFollowing is the code to change the const variable, which would only display the initial value −const details1 = { firstName: 'David', subjectDetails: { subjectName: 'JavaScript' } } const details2 = { ...details1, subjectDetails: { ...details1.subjectDetails }, firstName: 'David' } details2.subjectDetails.subjectName = 'Java ' console.log(details1);To run the above program, you need to use the following command ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
123 Views
Let’s say the following are our objects −var object1 = { firstName: "David" }; var object2 = { firstName: "David" };You will not get the correct result using comparison operator (== or ===). Use JSON.stringify() for this.ExampleFollowing is the code implementing both the ways and showing the correct result −var object1 = { firstName: "David" }; var object2 = { firstName: "David" }; if (object1 == object2) console.log("using == operator result ==> true"); else console.log("using == operator result ==> false"); if (JSON.stringify(object1) == JSON.stringify(object2)) console.log("using JSON.stringify() operator result ==> true"); else console.log("using JSON.stringify() operator result ==> ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
2K+ Views
Let’s say the following are our array of objects:const details = [ { employeeFirstName: "John", employeeLastName: "Doe" }, { employeeFirstName: "David", employeeLastName: "Miller" }, { employeeFirstName: "John", employeeLastName: "Smith" } ]ExampleFollowing is the code to fetch specific values, in this case with first name “John” −const details = [ { ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
63 Views
Let’s say the following is our array object −var arrayObject = [ "John", "David", "Mike" ]Use length property to set the length to 0 and clear memory.The syntax is as follows to clear memory and allocate again −yourArrayObjectName.length=0; // To clear memory yourArrayObjectName.length=4; // To allocate memoryExampleFollowing is the code −var arrayObject = [ "John", "David", "Mike" ] arrayObject.length = 0; console.log(arrayObject); arrayObject.length = 5; for (var i = 0; i < arrayObject.length; i++) console.log(arrayObject[i]);To run the ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
197 Views
To fetch alternative values, use the array index and check with the following condition −if(index%2==0) { // code } The above will display the even values.ExampleFollowing is the code −var subjectsName=["MySQL","JavaScript","MongoDB","C","C++","Java"]; for(let index=0;index node demo222.js Subject name at even position=MySQL Subject name at even position=MongoDB Subject name at even position=C++
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
125 Views
Use get keyword to make getter function.ExampleFollowing is the code −const studentDetails = { studentName: "David Miller", get studentName() { console.log('I am calling the getter method...') } } console.log(studentDetails.studentName);To run the above program, you need to use the following command −The output is as follows −node fileName.js.Here, my file name is demo221.js.OutputThe output is as follows −PS C:\Users\Amit\JavaScript-code> node demo221.js I am calling the getter method... Undefined
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
208 Views
For this, use the “this” keyword.ExampleFollowing is the code −class Employee { constructor() { this.tempObject = [ { firstName: "David", setTheAnotherFirstName() { this.firstName = "Carol"; }, }, ]; } } var empObject = new Employee(); empObject.tempObject[0].setTheAnotherFirstName(); console.log("The Change First Name is=" + empObject.tempObject[0].firstName);To run the above program, you need to use the following command −node fileName.js. Here, my file name is demo220.js.OutputThe output is as follows −PS C:\Users\Amit\JavaScript-code> node demo220.js The Change First Name is=Carol
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
910 Views
Let’s say we have the following variables −var value1 = 10; var value2 = 10.15;Use the Number() condition to check that a number is float or integer −Number(value) === value && value % 1 !== 0; }ExampleFollowing is the code −function checkNumberIfFloat(value) { return Number(value) === value && value % 1 !== 0; } var value1 = 10; var value2 = 10.15; if (checkNumberIfFloat(value1) == true) console.log("The value is float=" + value1); else console.log("The value is not float=" + value1); if (checkNumberIfFloat(value2) == true) console.log("The value is float=" + value2); else console.log("The value is not ... Read More