V Jyothi

V Jyothi

54 Articles Published

Articles by V Jyothi

Page 2 of 6

How to define integer constants in JavaScript?

V Jyothi
V Jyothi
Updated on 15-Mar-2026 1K+ Views

ECMAScript allows usage of const to define constants in JavaScript. To define integer constants in JavaScript, use the const keyword. Syntax const CONSTANT_NAME = value; Example const MY_VAL = 5; console.log("MY_VAL:", MY_VAL); // This will throw an error try { MY_VAL = 10; } catch (error) { console.log("Error:", error.message); } MY_VAL: 5 Error: Assignment to constant variable. Key Points As shown above, MY_VAL is a constant with value 5 assigned. Attempting to reassign another value to a constant ...

Read More

How to get Natural logarithm of 10 in JavaScript?

V Jyothi
V Jyothi
Updated on 15-Mar-2026 727 Views

To get the natural logarithm of 10 in JavaScript, use the Math.LN10 property. This built-in constant returns the natural logarithm of 10, which is approximately 2.302585092994046. Syntax Math.LN10 Return Value Returns a number representing the natural logarithm of 10 (ln(10) ≈ 2.302585092994046). Example JavaScript Math LN10 Property ...

Read More

How to define custom JavaScript exceptions?

V Jyothi
V Jyothi
Updated on 15-Mar-2026 242 Views

Custom JavaScript exceptions allow you to create specific error types for your application. You can throw custom error messages or create custom error classes for better error handling. Basic Custom Exception with String The simplest way to create a custom exception is by throwing a string message: function divide(a, b) { try { ...

Read More

Open a file browser with default directory in JavaScript and HTML?

V Jyothi
V Jyothi
Updated on 15-Mar-2026 1K+ Views

Opening a file browser with a default directory is not possible in JavaScript due to security restrictions. Web browsers prevent websites from accessing or setting specific file system paths to protect user privacy and system security. Why Default Directory Setting is Restricted Browsers block this functionality for several security reasons: Prevents websites from accessing sensitive system directories Protects user privacy by hiding file system structure Avoids potential security exploits through path manipulation Directory paths may not exist on different operating systems Standard File Input Behavior The HTML file input always opens in the ...

Read More

Which event occurs in JavaScript when an element's content is cut?

V Jyothi
V Jyothi
Updated on 15-Mar-2026 199 Views

The oncut event occurs when an element's content is cut using Ctrl+X or the right-click context menu. This event is commonly used with input fields, textareas, and other editable elements to track when users cut text. Syntax element.oncut = function() { // Code to execute when content is cut }; // Or using addEventListener element.addEventListener('cut', function(event) { // Code to execute when content is cut }); Example: Basic oncut Event Cut Event Example ...

Read More

How to detect point on canvas after canvas rotation in HTML5

V Jyothi
V Jyothi
Updated on 15-Mar-2026 337 Views

When working with HTML5 canvas rotation, detecting the correct coordinates of points becomes challenging because the canvas coordinate system changes. This article shows how to create a transform class to handle point detection after canvas rotation. The Problem When you rotate a canvas, the coordinate system rotates with it. A point at (5, 6) on the original canvas will have different coordinates after rotation. You need to transform these coordinates to match the rotated canvas. Creating a Transform Class Here's a complete Transform class that handles canvas rotations and point transformations: ...

Read More

Remove a FileList item from a multiple "input:file" in HTML5

V Jyothi
V Jyothi
Updated on 15-Mar-2026 2K+ Views

When working with HTML5 file inputs, you cannot directly modify the FileList object returned by input.files. The FileList is read-only, so removing items requires converting it to an array first. The Problem The FileList object from file inputs is immutable: Show Files Try Direct Removal function showFiles() { const files = document.getElementById('fileInput').files; document.getElementById('output').innerHTML = 'Files selected: ' + files.length; } function tryDirectRemoval() { const files = document.getElementById('fileInput').files; try { ...

Read More

What is the best way to initialize a JavaScript Date to midnight?

V Jyothi
V Jyothi
Updated on 15-Mar-2026 585 Views

To initialize a JavaScript Date to midnight, you need to set the time components (hours, minutes, seconds, and milliseconds) to zero using the setHours() method. Syntax date.setHours(hours, minutes, seconds, milliseconds) For midnight, use: date.setHours(0, 0, 0, 0) Example: Setting Current Date to Midnight var dt = new Date(); console.log("Original date:", dt.toString()); dt.setHours(0, 0, 0, 0); ...

Read More

What is the role of special characters in JavaScript Regular Expressions?

V Jyothi
V Jyothi
Updated on 15-Mar-2026 341 Views

Special characters in JavaScript regular expressions are metacharacters that define patterns for matching text. These characters control how many times a character or group should appear and where it should be positioned within a string. Quantifiers Quantifiers specify how many times the preceding character or group should match: Character Description + Matches one or more occurrences of the preceding character * Matches zero or more occurrences of the preceding character ? Matches zero or one occurrence of the preceding character {n} Matches exactly n ...

Read More

What is onsubmit event in JavaScript?

V Jyothi
V Jyothi
Updated on 15-Mar-2026 4K+ Views

The onsubmit event is an event that occurs when you try to submit a form. You can put your form validation against this event type. The following example shows how to use onsubmit. Here we are calling a validate() function before submitting a form data to the web server. If validate() function returns true, the form will be submitted, otherwise, it'll not submit the data. Syntax // form elements // Or using JavaScript form.onsubmit = function(event) { // validation logic return true; ...

Read More
Showing 11–20 of 54 articles
Advertisements