Found 9291 Articles for Object Oriented Programming

Array.prototype.find() method in JavaScript.

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

100 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

230 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

244 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

95 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

830 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

467 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?

AmitDiwan
Updated on 16-Jul-2020 12:27:48

1K+ Views

You can use the concept of focus(). Following is the JavaScript code −Example Live Demo Document TEXT BOX FOR FOCUS click me to get the tab on focus    document.getElementById('focusButton').addEventListener('click', function() {       document.querySelectorAll('.TEXT_FOCUS')[0].focus();    }); To run the above program, save the file name anyName.html(index.html) and right click on the file and select the option open with live server in VS code editor.OutputWhen you click the button, the focus will be on a particular element. The snapshot is as follows −

Highlight a text, every time page loads with JavaScript

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

250 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

Window innerWidth and innerHeight Properties in JavaScript.

AmitDiwan
Updated on 16-Jul-2020 07:37:06

113 Views

The innerWidth property returns the width of the window content area and the innerHeight property returns the width of the window content area.Following is the code for window innerWidth and innerHeight properties in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result{       font-size: 20px;       font-weight: 500;    } Window innerWidth and innerHeight Properties CLICK HERE Click on the above button get the innerWidth and innerHeight of the window.    let ... Read More

Type casting in JavaScript.

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

5K+ Views

Type casting means conversion of one data type to another explicitly. In JavaScript some of the most common methods to convert a datatype to either string using String(), to boolean using Boolean(), or to number using Number().Following is the code for type casting in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result, .sample {       font-size: 20px;       font-weight: 500;    } Type casting in JavaScript. 44 CLICK HERE Click on the above button ... Read More

Advertisements