Found 9150 Articles for Object Oriented Programming

How to delete object properties in JavaScript?

AmitDiwan
Updated on 15-Jul-2020 13:21:27

184 Views

Following is the code for deleting object properties in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result, .sample {       font-size: 20px;       font-weight: 500;    } Delete object properties in JavaScript Before Deleting After deleting CLICK HERE Click on the above button to delete object properties    let btnEle = document.querySelector(".btn");    let resEle = document.querySelector(".result");    let sampleEle = document.querySelector(".sample");    let obj = {       firstName: ... Read More

How to create an object and access its properties in JavaScript?

AmitDiwan
Updated on 15-Jul-2020 13:18:51

233 Views

Following is the code creating an object and accessing its properties in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 20px;       font-weight: 500;    } Hoisting in JavaScript CLICK HERE Click on the above button to create and access a object    let btnEle = document.querySelector(".btn");    let resEle = document.querySelector(".result");    let obj = {       firstName: "Rohan",       lastName: "Sharma",   ... Read More

Explain hoisting in JavaScript

AmitDiwan
Updated on 15-Jul-2020 13:16:02

380 Views

Hoisting allows us to call functions and variables (declared with var) before they are being defined by moving them to the top of their scope before the execution of code begins.Following is the code showing hoisting for variables and functions in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result, .sample {       font-size: 20px;       font-weight: 500;    } Hoisting in JavaScript Calling functions and variables before they are defined CLICK HERE ... Read More

How to import and export a module/library in JavaScript?

AmitDiwan
Updated on 15-Jul-2020 13:12:59

2K+ Views

Note − To run this example you will need to run a localhost server.Following is the code for importing and exporting a module/library in JavaScript −ExampleINDEX.html Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 18px;       font-weight: 500;    } JavaScript Importing and Exporting Modules IMPORT Click on the above button to import module script.jsimport test from './sample.js'; document.querySelector('.Btn').addEventListener('click', ()=>{    test(); })sample.jslet resultEle = document.querySelector(".result"); export default ... Read More

Explain ‘dotAll’ flag for regular expressions in JavaScript

AmitDiwan
Updated on 15-Jul-2020 13:09:01

243 Views

The dotAll flag returns true or false depending upon if the s flag has been set in the regular expression or not.Following is the code to implement dotAll flag for regular expressions in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 20px;       font-weight: 500;    } dotAll flag for regular expressions CLICK HERE Click on the above button to know if s flag has been set in regex or ... Read More

Explain the callback Promise.finally in JavaScript

AmitDiwan
Updated on 15-Jul-2020 13:06:56

202 Views

The promise.finally() calls the callback function whether a promise has been fulfilled or rejected. This helps us to do something once the promise has been rejected or resolved.Following is the code for Promise.finally() in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 20px;       font-weight: 500;    } Promise.finally in JavaScript CLICK HERE Click on the above button to know when the promise finishes    let btnEle = ... Read More

Named capture groups JavaScript Regular Expressions

AmitDiwan
Updated on 15-Jul-2020 13:03:30

177 Views

With JavaScript, you can group s part of regular expression. This can be done by encapsulating characters in parentheses.Following is an example −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .sample, .result {       font-size: 20px;       font-weight: 500;    } Named capture groups Regular Expressions The year in which i passed school was 2012. CLICK HERE Click on the above button to extract the year using named groups    let sampleEle = ... Read More

Lookbehind Assertions JavaScript Regular Expressions

AmitDiwan
Updated on 15-Jul-2020 12:57:57

161 Views

Lookbehind allows matching a pattern only if there’re something before.Following is an example −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .sample, .result {       font-size: 20px;       font-weight: 500;    } Look behind Assertions Regular Expressions The price for 4 tables are $50 , $99 , $121 and $150. CLICK HERE Click on the above button to extract the table price using lookbehind    let sampleEle = document.querySelector(".sample").innerHTML;    let btnEle = document.querySelector(".btn");    let resEle = document.querySelector(".result");    const priceRegex=/(? {       resEle.innerHTML = "Table price are = "+sampleEle.match(priceRegex);    }); OutputThe above code will produce the following output −On clicking the ‘CLICK HERE’ button −

Unicode Property Escapes JavaScript Regular Expressions

AmitDiwan
Updated on 15-Jul-2020 12:56:25

206 Views

The Unicode property escapes regular expressions, allow us to match characters based on their Unicode properties by using the flag u.ExampleFollowing is an example − Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .sample, .result {       font-size: 20px;       font-weight: 500; } Unicode Property Escapes JavaScript Regular Expressions Hello 😆😀 World 🙂😊 CLICK HERE Click on the above button to extract the emojis using regex    let sampleEle = document.querySelector(".sample").innerHTML;    let btnEle ... Read More

Rest and Spread operators in JavaScript

AmitDiwan
Updated on 15-Jul-2020 12:53:19

6K+ Views

The rest operator (…) allows us to call a function with any number of arguments and then access those excess arguments as an array. The rest operator also allows us in destructuring array or objects.The spread operator (…) allows us to expand an iterable like array into its individual elements.ExampleFollowing is the code showing the rest and spread operator in JavaScript − Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .sample, .result {       font-size: 20px;       font-weight: 500;    } ... Read More

Advertisements