Explain for...in Statement in JavaScript

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

142 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

Lambdas with Arrow Functions in JavaScript

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

1K+ 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

Read Data from JSON Array Using JavaScript

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

4K+ 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

Parse and Show Current Time Stamp of HTML Audio Player in JavaScript

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

1K+ 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

JavaScript eval() Function: Rules and Usage

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

134 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

Best Way to Open New Browser Window Using JavaScript

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

252 Views

The open() method of window object is the best way to open new browser window using JavaScriptFollowing is the code for opening new browser window using JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    } Open new browser window using JavaScript CLICK HERE Click on the above button open a new browser window    let BtnEle = document.querySelector(".Btn");    BtnEle.addEventListener("click", (event) => {       window.open("https://www.google.com");    }); OutputOn clicking the ‘CLICK HERE’ button, it will redirect to the specified website −

Verify if a JavaScript Variable is Loaded

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

2K+ Views

To verify if a JavaScript variable has been loaded or not, we can check if it is undefined or has a null value by doing comparison for both the values. We can also use typeof() since it returns string always to know if variable has been loaded or not.Following is the code to verify if a JavaScript variable has been loaded or not −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 20px;       font-weight: 500;   ... Read More

Pass Arguments to Anonymous Functions in JavaScript

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

1K+ Views

Following is the code for passing arguments to anonymous functions in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-weight: 500;       font-size: 20px;       color: blueviolet;    } Pass arguments to anonymous functions CLICK HERE Click on the above button to call an anonymous function and pass parameters to it    let BtnEle = document.querySelector(".Btn");    let resEle = document.querySelector(".result");    let add = function (a, b) {       return a + b;    };    BtnEle.addEventListener("click", (event) => {       resEle.innerHTML = "The sum of 22 and 19 = " + add(22, 19);    }); OutputOn clicking the ‘CLICK HERE’ button −

Get Child Element of a Parent Using JavaScript

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

567 Views

Following is the code for getting the child element of a parent using JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .child1,    .child2,    .child3 {       display: none;       margin: 10px;       width: 70px;       height: 70px;    }    .child1 {       background-color: red;    }    .child2 {       background-color: pink;    }    .child3 {       background-color: blue;    } Get ... Read More

Uses of the JavaScript with Statement

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

1K+ Views

The WITH statement is used to specify the default object for the given property and allow us to prevent writing long lengthy object references. It adds the given object to the head of the scope chain.Following is the code for with statement in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 20px;       font-weight: 500;    } JavaScript with statement CLICK HERE Click on the above button to get the first ... Read More

Advertisements