Create a New Data Type in JavaScript

Yaswanth Varma
Updated on 21-Apr-2023 17:03:31

2K+ Views

The task we are going to perform in this article is it possible to create a new data type in JavaScript. For instance, let’s consider we have variable student − var student = "username" console.log(typeof student) Now, I want to declare the type of that variable and print that in the output, and it will look like this − Output:"string" Let’s dive into the article to learn more about creating a new data type in JavaScript. Yes, it is possible to create a new data type in JavaScript, you can use the concept of Class. If you want ... Read More

Change Tag's Inner HTML Based on Order in JavaScript

Yaswanth Varma
Updated on 21-Apr-2023 17:01:34

683 Views

The innerHTML property of an element in JavaScript allows you to access or modify any HTML or XML markup that is there. Use the method insertAdjacentHTML () to insert HTML into the page as opposed to changing an element's content. In JavaScript to change a tag’s innerHTML based on their order can be done using document.querySelectorAll(). Let’s jump into the article to learn more about changing the tag’s innerHTML based on their order. Using document.querySelectorAll() The static NodeList returned by the Document function querySelectorAll() lists all of the document's elements that match the given set of selectors. Syntax Following is ... Read More

Convert Date to Another Timezone in JavaScript

Saurabh Jaiswal
Updated on 21-Apr-2023 17:00:51

10K+ Views

JavaScript has a new Date() constructor which is used to create a date object to get the current date and time. This date object uses the UTC timezone or the client browser's timezone, i.e. if you are in India and use the new Date() constructor to get the date and time, you will get your local time. But sometimes, we may need to get the timezone of another country, which we can't do directly. These can be done using the toLocaleString() method or the format() method. By the end of the article, you will be able to get the date ... Read More

Format Date Value in JavaScript

Yaswanth Varma
Updated on 21-Apr-2023 16:59:26

470 Views

To obtain dates in JavaScript, use either the new Date() or Date() function Object() { [native code] } (either current date or a specific date). While the Date() function Object()produces a string containing the current date and time, the new Date() function Object()creates a new Date object. Let’s dive into the article for getting better understanding on how to format date value in JavaScript How to Format Dates in JavaScript? Date formatting is dependent on you and your requirements. In some nations, the year (06/22/2022) comes first, then the month. In other cases, the day precedes the month, the year ... Read More

Convert Decimal to Hex in JavaScript

Saurabh Jaiswal
Updated on 21-Apr-2023 16:59:14

2K+ Views

For any computer programmer who is working with low-level language or assembly language, it is a fundamental task to convert decimal to hex or hexadecimal. In web development we use colors and to represent them it is a common practice to use hex color codes. In Javascript, it is very easy to convert decimal to hexadecimal because of the built-in functions and methods provided by ECMA. In this article, we will discuss multiple ways to convert decimal to hex in javascript with appropriate examples. Using toString() method Using Custom Function Using the toString() Method As the name suggests ... Read More

Convert CFAbsoluteTime to Date Object and Vice Versa in JavaScript

Saurabh Jaiswal
Updated on 21-Apr-2023 16:58:31

474 Views

CFAbsoluteTime is the elapsed time since Jan 1, 2001, 00:00:00 UTC. This is a standard time format on Apple devices. On the other hand, a date object is a built-in object in JavaScript used to represent date and time values. It has many methods for providing formatting and converting date & time from one form to another. The main difference between CFAbsolute Time and JavaScript Date objects is their format. CFAabsolute time is a numeric value representing the number of milliseconds since the Unix epoch whereas a date object is an object representing a specific date and time, year, month, ... Read More

Capitalize a Word and Replace Spaces with Underscore in JavaScript

Yaswanth Varma
Updated on 21-Apr-2023 16:58:12

2K+ Views

We will try to develop a method to change text with spaces and lowercase letters into text with underscores, where the initial letter of each word is capitalized. Let's examine the equation in its entirety. tutorials point = Tutorials_Point //expected output Let’s dive into article for getting better understanding on capitalize a word and replace spaces with underscore JavaScript. Using replace() method The replace() method looks up a value or regular expression in a string. A new string with the replaced value() is the result of the replace() method. The original string is unchanged by the replace() technique. Syntax ... Read More

Convert Hyphens to Camel Case in JavaScript

Saurabh Jaiswal
Updated on 21-Apr-2023 16:57:25

2K+ Views

As a developer, we often encounter hyphenated strings. A hyphenated string makes our code more readable when the string’s length is high and the name is very complex. To solve this problem we use a camel case. Camel case is a very popular naming convention, in which we combine multiple words and make one string by capitalizing the first letter of each string except the first string. In javascript, we can use this convention to create variables and function names while we cannot use hyphenated strings to create a variable. In this article, we will explore step by step multiple ... Read More

Convert Hex to RGBA Value Using JavaScript

Saurabh Jaiswal
Updated on 21-Apr-2023 16:56:09

3K+ Views

While designing web pages we use colors to make web pages more appealing and engaging. We commonly use hex code to represent colors but sometimes we need to add transparency to the colors which can be achieved by RGBA values. Hex color values are represented by #RRGGBBAA and The RGBA color values are represented by rgba( red, green, blue, alpha). Here are a few examples of RGBA and hex values − Input: #7F11E0 Output: rgba( 127, 17, 224, 1 ) Input: #1C14B0 Output: rgba( 28, 20, 176, 1 ) In ... Read More

Run SASS Code from Command Line

Shubham Vora
Updated on 21-Apr-2023 16:54:46

398 Views

SASS is an abbreviation of Syntactically Awesome Style Sheets. It is a pre-process that compiles the code of SCSS and converts it into the CSS (cascading style sheet). It is a superset of CSS. This tutorial will teach us to compile the SCSS code using the terminal. Steps to run SASS From the Terminal Users should follow the below steps to run the SASS code from the terminal. Step 1 − Users should have installed Node.JS on their local computer. If not, Go to https://nodejs.org/en/download, download and install from there. Step 2 − Now, we need to create a ... Read More

Advertisements