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
Javascript Articles
Page 83 of 534
JavaScript global Property
The global property in JavaScript returns true or false depending upon if the ‘g’ modifier is set or not.Following is the code for JavaScript global property −Example Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .sample, .result { font-size: 18px; font-weight: 500; } JavaScript global Property Some random text inside a div CLICK HERE Click on the above button to check if the 'g' modifier is set or not let sampleEle ...
Read MoreJavaScript Immediately Invoked Function Expressions (IIFE)
The JavaScript Immediately Invoked Function Expressions (IIFE) is a JavaScript function that executes immediately after it has been defined so there is no need to manually invoke IIFE.Following is the code for Immediately Invoked Function Expressions (IIFE) in JavaScript −Example Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .sample { font-size: 18px; font-weight: 500; } JavaScript Immediately Invoked Function Expressions (IIFE) let sampleEle = document.querySelector(".sample"); (function () { sampleEle.innerHTML ="This code is invoked immediately as soon as it is defined"; })(); Output
Read MoreJavaScript JSON Arrays
Arrays in JSON are similar to Arrays in JavaScript. JavaScript JSON arrays looks like this −let obj = { name:'Rohan', sports : ['cricket','Football','volleyball','hockey'] }Following is the code for JSON arrays in JavaScript −Example Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .sample { font-size: 18px; font-weight: 500; } JSON arrays CLICK HERE Click on the above button to access JSON array let sampleEle = document.querySelector(".sample"); let obj = { name:'Rohan', sports : ['cricket','Football','volleyball','hockey'] } document.querySelector(".Btn").addEventListener("click", () => { obj.sports.forEach(item=>{ sampleEle.innerHTML += item + ''; }) }); OutputOn clicking the ‘CLICK HERE’ button −
Read MoreJavaScript JSON HTML
To generate HTML using JSON data, the code is as follows −Note − JSONPlaceholder is a fake Online REST API for Testing and PrototypingExample Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .sample { font-size: 18px; font-weight: 500; color: red; } JSON arrays EMPLOYEE NAME CLICK HERE Click on the above button to fill the employee table let sampleEle = document.querySelector(".employee"); document.querySelector(".Btn").addEventListener("click", () => { fetch("https://jsonplaceholder.typicode.com/users") .then((response) => response.json()) .then((result) => { result.forEach((element) => { sampleEle.innerHTML += "" + element.name; }); }); }); OutputOn clicking the ‘CLICK HERE’ button −
Read MoreJavaScript - know the value of GET parameters from URL
To know the value of GET parameters from URL in JavaScript, the code is as follows −Example Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .sample { font-size: 18px; font-weight: 500; color: red; } GET parameters from URL https://www.google.com?imageSize=440&color=blue CLICK HERE Click on the above button to get the imageSize and color value from the above URL let sampleEle = document.querySelector(".sample"); let resultEle = document.querySelector(".result"); var ...
Read MoreJavaScript lastIndex Property
The lastIndex property in JavaScript returns the index position when a match occurs and the next match then resumes from that position only. The lastIndex property works only if the ‘g’ modifier is set.Following is the code for the lastIndex property in JavaScript −Example Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .sample, .result { font-size: 18px; font-weight: 500; color: red; } JavaScript lastIndex Property The king bought an expensive ring. ...
Read MoreJavaScript Let
The JavaScript Let keyword introduced in 2015 allows us to define block scoped variables.Following is the code for declaring variable using Let keyword in JavaScript −Example Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .sample{ font-size: 18px; font-weight: 500; color: red; } JavaScript Let CLICK HERE Click on the above button to access the varible let sampleEle = document.querySelector(".sample"); document.querySelector(".Btn").addEventListener("click", () => { ...
Read MoreJavaScript Location protocol Property
The JavaScript location protocol property returns the protocol used by the current URL.Following is the code for Location protocol Property in JavaScript −Example Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .sample{ font-size: 18px; font-weight: 500; color: red; } Location protocol Property CLICK HERE Click on the above button to get the location protocol let sampleEle = document.querySelector(".sample"); document.querySelector(".Btn").addEventListener("click", () => { sampleEle.innerHTML = 'The protocol used by the website = ' + location.protocol; }); OutputOn clicking the “CLICK HERE” button −
Read MoreJavaScript multiline Property
The JavaScript multiline property returns true or false depending upon if the ‘m’ modifier has been set or not.Following is the code for the JavaScript multiline property −Example Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .sample, .result { font-size: 18px; font-weight: 500; color: red; } JavaScript Math Object The king bought the ring CLICK HERE Click on the above button to see if m modifier has been set or ...
Read MoreJavaScript Numbers example
Following is an example for numbers in JavaScript −Example Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .sample{ font-size: 18px; font-weight: 500; color: red; } JavaScript Numbers CLICK HERE Click on the above button to see numbers in JavaScript let sampleEle = document.querySelector(".sample"); let a =22; let b = 1.523; let c = 99; document.querySelector(".Btn").addEventListener("click", () => { sampleEle.innerHTML = 'a = ' + a + ''; sampleEle.innerHTML += 'b =' + b + ''; sampleEle.innerHTML += 'c = ' + c + ''; sampleEle.innerHTML += 'a + c = ' + (a+c) + ''; }); OutputOn clicking the ‘CLICK HERE’ button −
Read More