Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Articles on Trending Technologies
Technical articles with clear explanations and examples
Write a C program that won’t compile in C++
Here, we will write some c programs that won’t compile in c++. Though c++ is considered as a successor of c that has all its features and has compatibility with c code there are some programs that won’t compiler or given a compilation error when compiled with c++ compiler.A list of some of the C programs that won’t compile in c++ are −Call to a function before declaration − In c++, function call before declaration gives compilation error. But this works fine in c.Example Live Demo#include int main(){ printHello(); return 0; } void printHello(){ printf("TutorialsPoint"); }OutputTutorialsPointUsing typecasted ...
Read MoreJavaScript program to decrement a date by 1 day
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 −
Read MoreHow to find keys of a hash in JavaScript?
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 −
Read MoreHow can we validate decimal numbers in JavaScript?
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 MoreHow can I remove a child node in HTML using JavaScript?
Following is the code to remove a child node in HTML using JavaScript −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result { font-size: 20px; font-weight: 500; } Removing a child node in HTML using JavaScript Cow Lion Tiger Buffalo CLICK HERE Click the above button to remove the first list element from the above list let resEle = document.querySelector(".result"); let animalList = document.querySelector(".animal"); document.querySelector(".Btn").addEventListener("click", () => { animalList.removeChild(animalList.childNodes[0]); animalList = animalList; }); OutputThe above code will produce the following output −On clicking the ‘CLICK HERE’ button −
Read MoreHow to load a JavaScript file Dynamically?
Following is the code to load a JavaScript file dynamically −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result { font-size: 20px; font-weight: 500; } Load a JavaScript file Dynamically CLICK HERE Click the above button to load external JavaScript let resEle = document.querySelector(".result"); document.querySelector(".Btn").addEventListener("click", () => { var jsRef = document.createElement("script"); jsRef.setAttribute("src", "sample.js"); document.getElementsByTagName("head")[0].appendChild(jsRef); }); script.jsresEle.innerHTML='JavaScript has been loaded';OutputThe above code will produce the following output −On clicking the ‘CLICK HERE’ button −
Read MoreNamed arguments in JavaScript.
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 MoreCan we have a return statement in a JavaScript switch statement?
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 MoreCreating ‘Copy to Clipboard’ feature on a web page with JavaScript
Following is the code for creating ‘copy to clipboard’ feature on a web page with JavaScript −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result { font-size: 18px; font-weight: 500; color: rebeccapurple; } input, button { padding: 8px; } Creating Copy to Clipboard Copy Text Click on the above button to copy text from the textbox let resEle = document.querySelector(".result"); ...
Read MoreHow to disable mouse event on certain elements using JavaScript?
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