
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

356 Views
Let’s say, we are matching the current date and time with the business hours. We need to display whether the office is closed or open right now on the basis of current time.Get the hours from the current date and can use the ternary operator for close and open. Following is the code −Example Live Demo Document const gettingHours = new Date().getHours() const actualHours = (gettingHours >= 10 && gettingHours < 18) ? 'Open' : 'Closed'; document.querySelector('.closeOrOpened').innerHTML = actualHours; To run the above program, save ... Read More

611 Views
The recursive function calls itself with some base condition. Let’s say the following is our array with marks −var listOfMarks=[56, 78, 90, 94, 91, 82, 77];Following is the code to get the count of array elements −Examplefunction countNumberOfElementsUsingRecursive(listOfMarks) { if (listOfMarks.length == 0) { return 0; } return 1 + countNumberOfElementsUsingRecursive(listOfMarks.slice(1)); } var listOfMarks=[56, 78, 90, 94, 91, 82, 77]; console.log("The array="); console.log(listOfMarks); var numberOfElements=countNumberOfElementsUsingRecursive(listOfMarks); console.log("The Number of elements = "+numberOfElements);To run the above program, you need to use the following command −node fileName.js.Here, my file name is demo110.js.OutputThis will produce the following ... Read More

236 Views
Let’s say, first, we will set the start and end range and call the function:console.log(getRandomValueBetweenTwoValues(400, 480))We have passed start value 400 and end value 480. Let’s get the random value with Math.random() in JavaScript −Examplefunction getRandomValueBetweenTwoValues(startRange, endRange) { return Math.floor(Math.random() * (endRange - startRange + 1) + startRange); } console.log(getRandomValueBetweenTwoValues(400, 480))To run the above program, you need to use the following command −node fileName.js.Here, my file name is demo109.js.OutputThis will produce the following output −PS C:\Users\Amit\JavaScript-code> node demo109.js 401

4K+ Views
To check whitespace in a string, use the concept of indexOf(‘ ’). Following is the code −Examplefunction stringHasTheWhiteSpaceOrNot(value){ return value.indexOf(' ') >= 0; } var whiteSpace=stringHasTheWhiteSpaceOrNot("MyNameis John"); if(whiteSpace==true){ console.log("The string has whitespace"); } else { console.log("The string does not have whitespace"); }To run the above program, you need to use the following command −node fileName.js.Here, my file name is demo108.js.OutputThis will produce the following output −PS C:\Users\Amit\JavaScript-code> node demo108.js The string has whitespace

1K+ Views
You can use match() with passing the variable name. The syntax is as follows −console.log(yourVariableName.match(yourMatchingVariableName));Examplevar senetence = 'My Name is John'; console.log("The actual value="); console.log(senetence); var matchWord = 'John'; console.log("The matching value="); console.log(matchWord); var matchRegularExpression = new RegExp(matchWord, 'g' ); console.log(senetence.match(matchWord));To run the above program, you need to use the following command −node fileName.js.Here, my file name is demo107.js.OutputThis will produce the following output −PS C:\Users\Amit\JavaScript-code> node demo107.js The actual value= My Name is John The matching value= JohnRead More

423 Views
Let’s say we have the following records of studentId and studentName and want to check a specific student name −const studentDetails= [ { studentId:101, studentName:"John" }, { studentId:102, studentName:"David" }, { studentId:103, studentName:"Carol" } ]Create a custom function to find by name. Following is the code −Exampleconst studentDetails= [ { studentId:101, studentName:"John" }, { studentId:102, studentName:"David" }, { studentId:103, studentName:"Carol" } ] function findByName(name){ var flag=true; for(var i=0;i node demo106.js The name found=David

2K+ Views
Hibernate and Eclipse link both are object relational mapping tool. They both are the implementation of JPA.Hibernate is very popular implementation of JPA built by Red hat. It also has some extra features that JPA does not provide.Eclipse is an open source implementation of JPA built by Eclipse foundation. It 'is one of the first project which became part of EE4J. It is available in two forms −Eclipse link jar file format − It is complete package. It has everything which need to run any Eclipse link functionality.OSGI bundles for each of the eclipse link component.Sr. No.KeyHibernateEclipse link1BasicIt is a ... Read More

3K+ Views
Let’s say the following is our HTML button −Click the button to add the input into the belowText BoxUse document.getElementById() to add a text in on button click. Following is the code −Example Live Demo Document Click the button to add the input into the below Text Box document.getElementById("clickButton").addEventListener("click", () =>{ document.getElementById("readTheInput").value += "JavaScript"; }); To run the above program, save the file name “anyName.html(index.html)” and right click on the file. Select the option “Open with Live Server” in VS Code editor.OutputThis will produce the following ... Read More

1K+ Views
In order to convert string into camel case, you need to lowercase the first letter of the word and the first letter of the remaining words must be in capital.Following is the code to convert any string into camel case −Examplefunction convertStringToCamelCase(sentence) { return sentence.replace(/(?:^\w|[A-Z]|\b\w|\s+)/g, function(camelCaseMatch, i) { if (+camelCaseMatch === 0) return ""; return i === 0 ? camelCaseMatch.toLowerCase() : camelCaseMatch.toUpperCase(); }); } console.log(convertStringToCamelCase("Add two variables"));To run the above program, you need to use the following command −node fileName.js.Here, my file name is ... Read More