Found 9150 Articles for Object Oriented Programming

How to declare Block-Scoped Variables in JavaScript?

AmitDiwan
Updated on 16-Jul-2020 08:14:16

219 Views

To declare block scoped variables, we use the keyword let and const introduced in ES2015.Following is the code showing declaring black scoped variables in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result, .sample {       font-size: 20px;       font-weight: 500;    } Declaring block scoped variables CLICK HERE Click on the above button to declare and display block scoped variables    let resEle = document.querySelector(".result");    let sampleEle = document.querySelector(".sample");{     ... Read More

How to remove elements using the splice() method in JavaScript?

AmitDiwan
Updated on 16-Jul-2020 08:11:26

299 Views

Following is the code for removing elements using splice() method in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .sample,.result {       font-size: 20px;       font-weight: 500;    } Remove elements using splice() CLICK HERE Click on the above button to remove elements between 1st and 5th element    let fillEle = document.querySelector(".sample");    let resEle = document.querySelector(".result");    let arr = [1, 3, 5, 7, 9, 11];    fillEle.innerHTML = arr;    document.querySelector(".Btn").addEventListener("click", () => {       arr.splice(1, 4);       resEle.innerHTML = "Spliced array = " + arr;    }); OutputThe above code will produce the following output −On clicking the ‘CLICK HERE’ button −

Array.prototype.find() method in JavaScript.

AmitDiwan
Updated on 16-Jul-2020 08:07:16

160 Views

The Array.prototype.find() method returns the first element value that satisfy a given condition in an array.Following is the code for the Array.prototype.find() method −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .find {       font-size: 20px;       font-weight: 500;    } JavaScript Array Find() example CLICK HERE Click on the above button to find lion among the animals    function findLion(animal) {       return animal === "lion";    }    let fillEle = ... Read More

Explain JavaScript Error Object.

AmitDiwan
Updated on 16-Jul-2020 07:55:04

316 Views

The error object is basically thrown by the JavaScript interpreter when a script error occurs. This error object can also be thrown as exception for user defined exceptions. The two javaScript error object properties are −PropertyDescriptionnameIt sets or returns the name of the error.messageIt sets or returns the error message as stringFollowing is the code for error object in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 20px;       font-weight: 500;    } ... Read More

Block Scoping in JavaScript.

AmitDiwan
Updated on 16-Jul-2020 07:52:12

309 Views

Block scope is an area between two { curly braces } which can be between loops, if condition or switch statement. The let and const introduced in ES2015 allow us to create block scoped variables that can be accessed only inside those block.Following is the code showing block scoping in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result{       font-size: 20px;       font-weight: 500;    } Block scoping in JavaScript CLICK HERE Click on ... Read More

How to invoke a function as a function and method?

AmitDiwan
Updated on 16-Jul-2020 07:46:22

137 Views

Following is the code on invoking a function as a function and method −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result{       font-size: 20px;       font-weight: 500;    } Invoke a function as function and method CLICK HERE Click on the above button to invoke function as function and method    let resEle = document.querySelector(".result");    function add(a, b){       return a+b;    }    let obj = {   ... Read More

Parameters & Arguments in JavaScript.

AmitDiwan
Updated on 16-Jul-2020 07:44:25

982 Views

Function parameters are the names of variables present in the function definition. Function arguments are the real values that are passed to the function and received by them.Following is the code showing parameters and arguments in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result, .sample{       font-size: 20px;       font-weight: 500;    } Function parameters and arguments CLICK HERE Click on the above button to pass the above values as arguments to ... Read More

encodeURI() and decodeURI() functions in JavaScript.

AmitDiwan
Updated on 16-Jul-2020 07:41:28

567 Views

The encodeURI() function encodes the complete URI including special characters except except (, / ? : @ & = + $ #) characters.The decodeURI() function decodes the URI generated by the encodeURI() function.Following is the code for encodeURI() and decodeURI() functions in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .encode, .decode {       font-size: 18px;       font-weight: 500;    } encodeURI() and decodeURI() function in JavaScript ENCODE URI DECODE URI Click on ... Read More

JavaScript focus a particular element with div class, not div id declaration?

Alshifa Hasnain
Updated on 04-Mar-2025 19:49:21

2K+ Views

In this article, we will learn to focus on a particular element with a div class in JavaScript. In JavaScript setting focus on an element is commonly done using the focus() method. What is the focus() method? The focus() method in JavaScript is used to bring a specific element into focus. This means the element becomes active, allowing the user to interact with it, such as typing in an input field or highlighting a section of the webpage. Syntax element.focus(); Here, the element is the DOM element that will receive the focus. Using JavaScript to Focus on a Class Element ... Read More

Highlight a text, every time page loads with JavaScript

AmitDiwan
Updated on 16-Jul-2020 07:33:13

308 Views

To highlight a text, every time page loads, use the for loop and the concept of −Example Live Demo Document    .yellow {       color: yellow;    }    .blue {       color: blue;    } My yellow Words, your blue Words    var ids = document.getElementById("pageLoads");    var loadColorWords = ids.innerHTML.split(" ");    for(var i = 0; i < loadColorWords.length; i++) {       if(loadColorWords[i] == "blue") {          loadColorWords[i] = "" + loadColorWords[i] + "";       } ... Read More

Advertisements