In CSS, class names or selectors are used to select a particular HTML element. There are some CSS rules to define the class names or CSS selectors. In this tutorial, we will learn all CSS rules and about valid characters to create class names. Here are the rules for creating CSS class names. Rule 1 − Class name or CSS selectors should only contain alphanumeric characters and some special characters such as hyphens (-) and underscores (_). Rule 2 − Class names can’t start with the digits. For example, the “12sd” class name is invalid. Rule 3 − Class ... Read More
The task at hand is to learn how to remove all blank objects from a JavaScript object. Let’s consider the following object − const details = { name: 'John', age: {}, marks: { marks: {} } } We need to remove the black objects above You can use forEach() along with typeof and delete to remove blank objects. Let’s dive into the article for getting better understanding on removing blank objects. Using reduce() A reducer function is run for each element of an array using the reduce() method. The function's ... Read More
Characters that are neither alphabetical nor numeric are known as special characters. Special characters are essentially all unreadable characters, including punctuation, accent, and symbol marks. Remove any special characters from the string to make it easier to read and understand. We use replace() method to replace all the special characters following another character. Using replace() method The JavaScript built-in method string.replace() can be used to replace a portion of a supplied string with another string or a regular expression. The original string won't alter at all. Syntax Following is the syntax for replace() − string.replace(searchValue, newValue) Let’s look into ... Read More
In JavaScript Arrays are used to store multiple values in a single variable. This is compared to a variable that can store only one value. Each item in an array has a number attached to it, called a numeric index, that allows you to access it. In JavaScript, arrays start at index zero and can be manipulated with various methods. This basically tells about true or false. If the item is found then it returns true, else false is returned. You can achieve the same in JavaScript arrays, using includes. Let’s dive into the article to understand more about the ... Read More
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. The task we are going to perform was how to create a password generator JavaScript. Let’s dive into the article for getting better understanding on creating a password generator. For this, use Math.random() to create random passwords. Using Math.random() method A floating-point pseudo-random number in the range [0, 1], 0 (inclusive), and 1(exclusive) is returned by the JavaScript function Math.random(). You can then resize this random number to fit the necessary range. Syntax Following is the ... Read More
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 give a ... Read More
A computer pattern or idea called recursion is present in many programming languages, including JavaScript. It is a feature used to build a function that repeatedly calls itself, but with a smaller input each time, until the intended outcome of the code is realized. In this article, we will return the correct value from a recursive indexof() function in JavaScript. Let’s dive into the article for a better understanding. Accurate value from the recursive indexof() function The position of the first occurrence of a value in a string is returned by the indexOf() method. -1 is returned by the indexOf() ... Read More
The task we are going to perform in this article is setting a default variable value to undefined in a function. Before we jump into the article, let’s understand what are functions in JavaScript. One of the core components of JavaScript are functions. In JavaScript, a function is comparable to a procedure-a collection of statements that carry out an action or compute a value. However, in order for a process to be considered a function, it must accept an input and produce an output with an evident connection between the input and the result. Let’s see how to set a ... Read More
Each value in an array is referred to as an element, and each element has a certain numerical location in the array, which is referred to as its index. Nested Arrays, a feature of JavaScript, allow us to create arrays inside arrays. One or more arrays can be used as the elements of nested arrays. Although the term may be a little unclear, as we look further, it is actually rather fascinating. Accessing and returning nested array In JavaScript, a nested array is described as an Array (Outer array) inside another array (inner array). One or more inner Arrays are ... Read More
The SASS is a CSS preprocessor that keeps the CSS code dry as it doesn’t allow repetition in the code. There are various directives available in the SASS, one of which is the @import directive. The ‘@import’ directive is used to import the code of one ‘.scss’ or ‘.sass’ file into another file and execute it during compilation. We can import the variables, functions, mixins, etc., from one file to another using the ‘@import’ directive. Syntax Users can follow the syntax below to use the ‘@import’ directive in the SASS to import the file. @import 'test' We have imported ... Read More