Found 6710 Articles for Javascript

Is it possible to change values of the array when doing foreach() in javascript?

Abdul Rawoof
Updated on 02-Sep-2022 11:38:10

6K+ Views

Array is a data type which can store multiple elements of similar data types. For example, array is declared as integer data type then it stores one or more elements of the integer data type. In arrays the element can be manipulated when they are in a loop by using any of the mathematical operations or so. For example, if the array elements are numbers, then the numbers can be multiplied by a fixed number or can be added or subtracted also. The change in the array elements can be done by using a user defined program and the result ... Read More

What's the difference between window.location and document.location?

Abdul Rawoof
Updated on 26-Aug-2022 11:56:00

2K+ Views

The window.location property The location property of a window (i.e. window.location) is a reference to a Location object; it represents the current URL of the document being displayed in that window. Since window object is at the top of the scope chain, so properties of the window.location object can be accessed without the window prefix. For example window.location.href can be written as location.href. The following section will show you how to get the URL of page as well as hostname, protocol, etc. using the location object property of the window object. You can use the window.location.href property to get the ... Read More

Difference between application/x-javascript and text/javascript content types?

Ayush Gupta
Updated on 02-Dec-2019 06:07:38

1K+ Views

The text/javascript content type is obsolete. This was used in the early days of Html.application/x-javascript was an experimental content type(hence the x-). You should not be using this in your application.The correct content type to use in browsers is application/javascript. This helps browsers accept the content as js code.

What is the replacement of lodash pluck() method?

Ayush Gupta
Updated on 02-Dec-2019 06:06:54

1K+ Views

Pluck has been removed from lodash 4. This is because it did the same thing as a map.As a replacement, you can use the map function in the following way −Exampleimport _ from 'lodash' const objects = [{ 'a': 1 }, { 'a': 2 }]; console.log(_.map(objects, 'a'))OutputThis will give the output −[1, 2]

Where is _.pluck() in lodash version 4?

Ayush Gupta
Updated on 02-Dec-2019 06:06:00

430 Views

Pluck has been removed from lodash 4. This is because it did the same thing as a map.As a replacement, you can use the map function in the following way −Exampleimport _ from 'lodash' const objects = [{ 'a': 1 }, { 'a': 2 }]; console.log(_.map(objects, 'a'))This will give the output −Output[1, 2]

Why doesn't JavaScript support multithreading?

Ayush Gupta
Updated on 02-Dec-2019 06:04:38

526 Views

JavaScript used to be single-threaded. It runs using what is called an event loop.The Event Loop has one simple job — to monitor the Call Stack and the Callback Queue. If the Call Stack is empty, it will take the first event from the queue and will push it to the Call Stack, which effectively runs it.JS in browsers doesn't support multithreading in the event loop as it is not needed for 99.999% of the websites. The event loop handles everything seamlessly.For the remaining apps, devs can use web workers. Web Workers are a simple means for web content to ... Read More

How to deserialize a JSON into Javascript object?

Aman Kumar
Updated on 19-Dec-2022 11:12:58

3K+ Views

Serialization is the process of converting an object such that it is transferable over the network. In JavaScript usually we serialize an Object into the JSON (or JavaScript Object Notation) format. To reserialize a JSON into a JavaScript object, we need to use the method JSON.parse(). JavaScript object notation is used to exchange data to or from a web server of the rest full API. The data we get from a web server is always a string variable, in order to use it we need to parse it with JSON.parse() which will return a JavaScript object or array object. Following ... Read More

How to test if a letter in a string is uppercase or lowercase using javascript?

Ayush Gupta
Updated on 02-Dec-2019 05:59:26

8K+ Views

To test if a letter in a string is uppercase or lowercase using javascript, you can simply convert the char to its respective case and see the result.Examplefunction checkCase(ch) {    if (!isNaN(ch * 1)){       return 'ch is numeric';    }     else {       if (ch == ch.toUpperCase()) {          return 'upper case';       }       if (ch == ch.toLowerCase()){          return 'lower case';       }    } } console.log(checkCase('a')) console.log(checkCase('A')) console.log(checkCase('1'))OutputThis will give the output −lower case upper case ch is numeric

What Is a JavaScript Framework?

Ayush Gupta
Updated on 02-Dec-2019 05:57:56

1K+ Views

JS frameworks are JavaScript code libraries that have pre-written code to use for routine programming features and tasks. It is literally a framework to build websites or web applications around.For example, in plain JS, you have to manually update the DOM using DOM APIs for setting styles updating content, etc.JS frameworks can help automate this repetitive task using features like 2-way binding and templating.Frameworks have their own way of doing things. For example, Angular is a popular JS framework that comes with many features like dependency injection, routing, etc and has its own way of building an application using it. ... Read More

What are the differences between clientHeight() and offsetHeight() in javascript?

Ayush Gupta
Updated on 02-Dec-2019 05:57:09

329 Views

You can use 2 properties, clientHeight and offsetHeight to get the height of the div.clientHeight includes padding of the div.offsetHeight includes padding, scrollBar, and borders of the div.ExampleFor example, if you have the following HTML −You can get the height using −const height = document.querySelector('#myDiv').offsetHeight console.log(height)OutputThis will give the output −400

Advertisements