Web Development Articles

Page 420 of 801

JavaScript program to take in a binary number as a string and returns its numerical equivalent in base 10

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 320 Views

We are required to write a JavaScript function that takes in a binary number as a string and returns its numerical equivalent in base 10. Therefore, let's write the code for the function. This one is quite simple, we iterate over the string using a for loop and for each passing bit, we double the number with adding the current bit value to it like this − Example const binaryToDecimal = binaryStr => { let num = 0; for(let i = 0; i < binaryStr.length; i++){ ...

Read More

JavaScript Auto-filling one field same as other

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 428 Views

Auto-filling form fields is a common requirement in web forms, especially when users need to copy address information between billing and shipping sections. This can be achieved using JavaScript event listeners and form field manipulation. Example body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; padding: 20px; } ...

Read More

JavaScript Const

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 350 Views

The JavaScript const declaration creates variables that cannot be reassigned to another value or redeclared later. It was introduced in ES2015 (ES6) and provides block scope like let but with immutable binding. Syntax const variableName = value; Basic const Example body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } Const Example Try ...

Read More

JavaScript Compare two sentences word by word and return if they are substring of each other

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 227 Views

The idea here is to take two strings as input and return true if one string is a substring of the other, otherwise return false. For example: isSubstr('hello', 'hello world') // true isSubstr('can I use', 'I us') // true isSubstr('can', 'no we are') // false In the function, we check which string is longer and then verify if the shorter string exists as a substring within the longer one. Syntax const isSubstr = (first, second) => { if (first.length > second.length) { ...

Read More

JavaScript Convert an array to JSON

Vivek Verma
Vivek Verma
Updated on 15-Mar-2026 2K+ Views

An array is a special object in JavaScript that stores multiple types of values, including integers, strings, and floats simultaneously. JSON (JavaScript Object Notation) is a lightweight data format used to represent structured data, commonly used for transmitting data between servers and web applications. In this article, we'll explore how to convert a JavaScript array into JSON format using the JSON.stringify() method. Understanding JSON.stringify() The JSON.stringify() method converts a JavaScript value or object into a JSON string. Since arrays are objects in JavaScript, we can pass an array as an argument to this method. Syntax ...

Read More

JavaScript – Getting Coordinates of mouse

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 532 Views

In JavaScript, you can get the coordinates of the mouse cursor using mouse event properties. The most common approach is to use the mousemove event listener along with event properties like clientX, clientY, pageX, and pageY. Mouse Coordinate Properties Different properties provide coordinates relative to different reference points: clientX, clientY - Coordinates relative to the viewport (visible browser window) pageX, pageY - Coordinates relative to the entire document (includes scrolled areas) screenX, screenY - Coordinates relative to the user's screen offsetX, offsetY - Coordinates ...

Read More

JavaScript encodeURI(), decodeURI() and its components functions

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 378 Views

JavaScript provides four essential functions for handling URI encoding and decoding. The encodeURI() function encodes complete URIs while preserving structural characters, whereas encodeURIComponent() encodes URI components including all special characters. Understanding the Functions The encodeURI() function encodes special characters in a URI except for reserved characters like , / ? : @ & = + $ # which are essential for URI structure. The encodeURIComponent() function encodes URI components by encoding all special characters including the reserved ones. The corresponding decode functions decodeURI() and decodeURIComponent() reverse the encoding process. Syntax encodeURI(uri) decodeURI(encodedURI) encodeURIComponent(uriComponent) decodeURIComponent(encodedURIComponent) ...

Read More

JavaScript Error message Property

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 273 Views

The message property of JavaScript Error objects contains a human-readable description of the error. It's automatically set when an error occurs and can also be customized when creating custom errors. Syntax error.message Example: Accessing Error Message JavaScript Error message Property body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .sample { font-size: 18px; ...

Read More

How to selectively retrieve value from json output JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 268 Views

We have the following data inside a JSON file data.json: data.json { "names": [{ "name": "Ramesh", "readable": true }, { "name": "Suresh", "readable": false }, { "name": "Mahesh", "readable": true }, { "name": "Gourav", "readable": true }, { "name": "Mike", "readable": false }] } ...

Read More

JavaScript Error name Property

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 232 Views

The name property of JavaScript Error objects identifies the type of error that occurred. It returns a string representing the error's name, which helps in debugging and error handling. Syntax error.name Common Error Names Different error types have specific names: ReferenceError - Variable or function not defined TypeError - Wrong data type used SyntaxError - Invalid syntax RangeError - Number out of range Example: Displaying Error Names Error Name Property ...

Read More
Showing 4191–4200 of 8,010 articles
« Prev 1 418 419 420 421 422 801 Next »
Advertisements