Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles by Yaswanth Varma
Page 16 of 31
How to create a password generator - JavaScript?
These days, password generators can be found all over the internet. Without a strong enough password, websites frequently won't let you establish an account. In this article, we'll learn how to create a password generator using JavaScript and the Math.random() method. Let's dive into creating a password generator step by step. We'll use Math.random() to generate cryptographically secure random passwords with customizable length and character sets. Understanding Math.random() The JavaScript Math.random() function returns a floating-point pseudo-random number between 0 (inclusive) and 1 (exclusive). We can scale this random number to select characters from our password character set. ...
Read MoreDetecting arrow key presses in JavaScript?
In JavaScript, detecting arrow key presses is essential for creating interactive web applications like games, navigation systems, and custom input controls. Arrow keys have specific key codes that JavaScript can detect through keyboard events. The four arrow keys have the following key codes: Left arrow: 37 Up arrow: 38 Right arrow: 39 Down arrow: 40 Method 1: Using keyCode with onkeydown The traditional approach uses the keyCode property to identify which arrow key was pressed: JavaScript Arrow Key Detection Click on the page and ...
Read MoreHow do I change a tag\'s inner HTML based on their order in JavaScript?
In JavaScript, you can change a tag's innerHTML based on their order using document.querySelectorAll() or getElementsByClassName(). These methods return collections of elements that you can iterate through and modify based on their position in the DOM. This technique is useful for numbering elements, adding order-based content, or applying different innerHTML to similar elements based on their sequence. Using document.querySelectorAll() The querySelectorAll() method returns a static NodeList containing all elements that match the specified CSS selector(s). Syntax document.querySelectorAll(selectors) Example 1: Basic Order Assignment Here's how to change innerHTML based on element order ...
Read MoreHow to convert a currency string to a double with jQuery or JavaScript?
Converting currency strings to numerical values is essential in web applications for calculations and data processing. This article demonstrates how to convert currency strings to doubles using JavaScript methods. There are two popular approaches to convert currency strings into numerical values using JavaScript built-in methods. We'll explore both methods with practical examples. Method 1: Using substring() and charCodeAt() This approach uses a loop to iterate through each character, checking if it's numeric using Unicode values: Use the charCodeAt() method to get the Unicode value of each character Use the substring() method to extract the numeric ...
Read MoreIs it possible to create a new data type in JavaScript?
The task we are going to perform in this article is to explore whether it's possible to create a new data type in JavaScript. For instance, let's consider we have a variable student: var student = "username"; console.log(typeof student); string Now, I want to declare a custom type for that variable and print that in the output. Let's dive into the article to learn more about creating a new data type in JavaScript. Can You Create Custom Data Types? Yes, it is possible to create custom data types in JavaScript using ...
Read MoreHow to format date value in JavaScript?
JavaScript provides several methods to format dates according to your requirements. The built-in Date object offers various formatting options, from simple string conversion to locale-specific formatting. Using toLocaleDateString() Method The toLocaleDateString() method formats dates according to locale and custom options, providing flexible date formatting. Example Here's how to format dates with custom options using toLocaleDateString(): var options = { year: 'numeric', ...
Read MoreI'm generating a list from an array. How can I know what element I'm clicking in JavaScript?
When generating lists from arrays in JavaScript, you need to identify which specific element a user clicked. This is essential for interactive applications where each list item should respond differently based on its data or position. Using Event Delegation Event delegation is the most efficient approach for handling clicks on dynamically generated elements. Instead of adding listeners to each element, you attach one listener to the parent container. const fruits = ['Apple', 'Banana', 'Orange', 'Mango']; ...
Read MoreHow to handle ESC keydown on JavaScript popup window?
When we press the escape key, the event generated is detected using the keyup and keydown event handlers. When the escape key is pushed on the keyboard, the event handler runs across the page. Let's dive into the article for getting better understanding on handling ESC keydown on JavaScript popup window. Using keydown Event When a key is pushed, the keydown event is triggered. The keydown event is called for all keys, regardless of whether they generate a character value, in contrast to the deprecated keypress event. While keypress shows which character was entered, keydown and keyup events ...
Read MoreJavaScript Insert space after every two letters in string?
In this article we are going to learn about how to insert space after every two letters in string. Before we jump into the article let's have a quick view on the strings in JavaScript. A sequence of one or more characters—which could be numbers, or symbols—is referred to as a string. Strings are immutable primitive data types in JavaScript, which means they cannot be changed. Let's dive into the article to learn more about inserting a space after every two letters in strings. For this, we'll explore multiple approaches using replace() with regular expressions and other methods. ...
Read MoreClear element.classList in JavaScript?
The task we are going to perform in this article is clear element classList in JavaScript. The classList property provides methods to add, remove, toggle, and check CSS classes on HTML elements. All element objects (i.e., objects that represent elements) in a Document derive from the most general base class called Element. It contains functions and characteristics that apply to all types of elements. What is classList in JavaScript JavaScript classList is a DOM property that enables manipulation of an element's CSS classes. The read-only classList property returns a DOMTokenList containing the CSS class names of an ...
Read More