Found 9297 Articles for Object Oriented Programming

When you should not use JavaScript Arrow Functions?

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

115 Views

The arrow functions should not be used as an object method because an arrow function does not have its own this. It takes this value of the enclosing lexical scope which is the window object instead of the object itself. This can cause problems as we would now be setting and accessing the window object properties instead of the intended object.Following is the code showing when should you not use JavaScript arrow functions −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {   ... Read More

Formatted Strings Using Template Strings in JavaScript

AmitDiwan
Updated on 18-Jul-2020 07:41:47

210 Views

Following is the code for formatted strings using template strings 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: blueviolet;    }    .sample {       color: red;    } Formatted Strings Using Template Strings JavaScript `The person name is ${personObj.name}. His age and rollno are ${personObj.age} and ${personObj.rollno} respectively` CLICK HERE Click on the above ... Read More

How to import an Object with Sub Objects and Arrays in JavaScript?

AmitDiwan
Updated on 18-Jul-2020 07:43:56

520 Views

Following is the code for importing an object with Sub objects and arrays in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result{       font-size: 18px;       font-weight: 500;    } Importing an Object with Sub Objects and Arrays let sampleEle = document.querySelector(".sample"); let obj = JSON.parse(sampleEle.innerHTML); script.jsimport obj from "./sample.js"; let resultEle = document.querySelector(".result"); for (let i in obj) {    resultEle.innerHTML += "Property = " + i + " : Value = " + obj[i] + ""; }sample.jsexport default{    firstName: "Rohan",    lastName: "Sharma",    school: {       name: "St Marks",       address: "USA",    },    sports: ["cricket", "football"], };OutputThe above code will produce the following output −

Spread operator for arrays in JavaScript

AmitDiwan
Updated on 18-Jul-2020 07:39:35

184 Views

The spread (…) syntax allow us to expand an iterable like array in places where 0+ arguments are expected. It allows us to pass a number of parameters as an array to a function.Following is the code to implement spread operator for arrays 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: blueviolet;    }    .sample {       color: red; } ... Read More

Effective Function Signatures with Default and Rest Parameters in JavaScript

AmitDiwan
Updated on 18-Jul-2020 07:37:05

61 Views

Following is the code for to implement function Signatures with Default and Rest Parameters in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 20px;       font-weight: 500;       color: blueviolet;    } Function Signatures with Default and Rest Parameters CLICK HERE Click on the above button to call the add() function with multiple parameters    let BtnEle = document.querySelector(".Btn");    let resEle = document.querySelector(".result");    function add(a ... Read More

Explain "for...in" statement in JavaScript?

AmitDiwan
Updated on 18-Jul-2020 07:36:57

103 Views

The for…in loop loops through all of the object properties. Following is the code o implement the for..in statement in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .sample, .result {       font-size: 18px;       font-weight: 500;       color: red;    } "for...in" statement in JavaScript {"firstName":"Rohan", "lastName":"Sharma", "age":22} CLICK HERE Click on the above button to traverse the above object using for..in loop    let sampleEle = document.querySelector(".sample");   ... Read More

How to read data from JSON array using JavaScript?

AmitDiwan
Updated on 18-Jul-2020 07:34:17

3K+ Views

Following is the code to read data from JSON array using JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .sample, .result {       font-size: 18px;       font-weight: 500;       color: red;    } Read data from JSON array using JavaScript [{"name":"Rohan", "age":22}, {"name":"Shawn", "age":12} ,{"name":"Michael", "age":21}] CLICK HERE Click on the above button to read data from above JSON array    let sampleEle = document.querySelector(".sample");    let resultEle = document.querySelector(".result"); ... Read More

Lambdas with Arrow Functions in JavaScriptLambdas with Arrow Functions in JavaScript

AmitDiwan
Updated on 18-Jul-2020 07:34:26

930 Views

Lambda function is a small anonymous function that consist of only one expression and can take one or multiple parameters. They basically allow functions to be passed as parameter to other functions. Since in JavaScript, functions are treated as object so they can be passed and returned from other functions to implement lambda functions.Following is the code for implementing lambdas with arrow functions in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .sample,    .result {       font-size: 20px;     ... Read More

JavaScript to parse and show current time stamp of an HTML audio player.

AmitDiwan
Updated on 18-Jul-2020 07:31:39

820 Views

Following is the code to to parse and show current time stamp of an HTML audio player −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 20px;       font-weight: 500;    } Show Current time stamp of an HTML audio player CLICK HERE Click on the above button to get the audio timestamp    let resEle = document.querySelector(".result");    let BtnEle = document.querySelector(".Btn");    let audioEle = document.querySelector(".audio");    BtnEle.addEventListener("click", () ... Read More

Explain JavaScript eval() function what are the rules to be followed while using it.

AmitDiwan
Updated on 18-Jul-2020 07:28:58

82 Views

The eval() function is used to evaluate the given string and execute it as JavaScript code. Using eval() is highly dangerous as someone can pass malicious code as input string to one of out inputs.Following is the code to show eval() function in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 20px;       font-weight: 500;    } JavaScript eval() function CLICK HERE Click on the above button to see eval() usage ... Read More

Advertisements