How to convert a string into an integer without using parseInt() function in JavaScript?

Imran Alam
Updated on 15-Mar-2026 23:19:00

2K+ Views

The parseInt() is a built-in function in JavaScript that parses a string and returns an integer. However, there are times when we want to convert a string into an integer without using this function. In this article, we'll explore several alternative methods to achieve this conversion. Using the Unary Plus Operator One way to convert a string into an integer is by using the unary plus operator (+). This operator converts its operand into a number. For instance, the following program converts the string "123" into the number 123: Unary Plus ... Read More

7 Best JavaScript IDE or Code Editors

Rushi Javiya
Updated on 15-Mar-2026 23:19:00

907 Views

In this tutorial, we'll discover the best software for JavaScript development. JavaScript makes your websites interactive and dynamic. You must pick a good JavaScript editor to write your code with ease. This article will give you a short introduction to the available JavaScript development tools with their pros and cons. JavaScript Code Editors vs IDEs There are two main types of development tools: code editors and IDEs (Integrated Development Environments). Code Editors are lightweight text tools focused on writing and editing code. They're fast, consume less memory, and work well on various devices including smartphones. ... Read More

Changing ternary operator into non-ternary - JavaScript?

AmitDiwan
Updated on 15-Mar-2026 23:19:00

386 Views

The ternary operator provides a concise way to write conditional expressions, but sometimes you need to convert it to regular if-else statements for better readability or debugging purposes. Understanding the Ternary Operator The ternary operator follows this syntax: condition ? valueIfTrue : valueIfFalse. It's a shorthand for simple if-else statements. Converting Ternary to If-Else Here's how to convert a ternary operator into a standard if-else statement: // Using ternary operator var number1 = 12; var number2 = 12; var result = (number1 == number2) ? "equal" : "not equal"; console.log("Ternary result:", result); // ... Read More

Picking all the numbers present in a string in JavaScript

AmitDiwan
Updated on 15-Mar-2026 23:19:00

195 Views

We are required to write a JavaScript function that takes in a string that contains some one-digit numbers in between and the function should return the sum of all the numbers present in the string. Example The code for this will be − const str = 'uyyudfgdfgf5jgdfj3hbj4hbj3jbb4bbjj3jb5bjjb5bj3'; const sumNum = str => { const strArr = str.split(""); let res = 0; for(let i = 0; i < strArr.length; i++){ if(+strArr[i]){ ... Read More

How to store two arrays as a keyvalue pair in one object in JavaScript?

AmitDiwan
Updated on 15-Mar-2026 23:19:00

791 Views

Suppose, we have two arrays of literals of same length like these − const arr1 = ['firstName', 'lastName', 'age', 'address', 'isEmployed']; const arr2 = ['Rahul', 'Sharma', 23, 'Tilak Nagar', false]; We are required to write a JavaScript function that takes in two such arrays. The function should construct an object mapping the elements of the second array to the corresponding elements of the first array. Method 1: Using Array.reduce() We will use the Array.prototype.reduce() method to iterate over the arrays, building the object. const arr1 = ['firstName', 'lastName', 'age', 'address', 'isEmployed']; ... Read More

Checking existence of all continents in array of objects in JavaScript

AmitDiwan
Updated on 15-Mar-2026 23:19:00

187 Views

Problem We are required to write a JavaScript function that takes in an array of objects that contains data about the continent of belonging for some people. Our function should return true if it finds six different continents in the array of objects, false otherwise. Example Following is the code − const people = [ { firstName: 'Dinesh', lastName: 'A.', country: 'Algeria', continent: 'Africa', age: 25, language: 'JavaScript' }, { firstName: 'Ishan', lastName: 'M.', country: 'Chile', continent: 'South America', age: 37, language: 'C' }, ... Read More

Checking for special numbers in JavaScript

Ranjit Kumar
Updated on 15-Mar-2026 23:19:00

594 Views

In JavaScript, checking for special numbers often involves mathematical operations on digits. A palindrome digit sum check determines if the sum of a number's digits forms a palindrome. Problem We need to write a JavaScript function that takes a number and returns true if the sum of its digits is a palindrome number, false otherwise. For example, with input 781296: const num = 781296; The expected output is: true Output Explanation The digit sum of 781296 is 7+8+1+2+9+6 = 33, which reads the same forwards and backwards (palindrome). ... Read More

How to convert a 2D array to a CSV string in JavaScript?

Imran Alam
Updated on 15-Mar-2026 23:19:00

1K+ Views

The CSV (Comma Separated Values) file format is a popular way of exchanging data between applications and data stores. The CSV file format is simple and easy to understand, and many applications and programming languages support it. In JavaScript, there are several ways to convert a 2D array into a CSV string. In this tutorial, we'll look at effective methods: using Array.map() with join(), and a manual approach for handling special cases. Using Array.map() with join() (Recommended) The most straightforward approach is to use Array.map() to process each row and join() to combine elements with commas. ... Read More

Examples of How 'text+=""' in JavaScript Work

Rushi Javiya
Updated on 15-Mar-2026 23:19:00

248 Views

In JavaScript, the text += "" notation combines the concatenation operator (+) with the assignment operator (=) to append content to an existing variable. This is particularly useful for building strings, HTML content, or any sequential data. The += operator adds the value on the right side to the variable on the left side and stores the result back in the same variable. When working with strings, it performs concatenation; with numbers, it performs addition. Basic Syntax variable += value; // Equivalent to: variable = variable + value; Simple Examples let text ... Read More

How do I check that a number is float or integer - JavaScript?

AmitDiwan
Updated on 15-Mar-2026 23:19:00

1K+ Views

In JavaScript, you can check if a number is a float (decimal) or integer using various methods. The most reliable approach uses the modulo operator to detect decimal values. Method 1: Using Modulo Operator The modulo operator % returns the remainder after division. For floats, value % 1 returns the decimal part: function checkNumberIfFloat(value) { return Number(value) === value && value % 1 !== 0; } var value1 = 10; var value2 = 10.15; if (checkNumberIfFloat(value1)) { console.log("The value is float=" + value1); } else { ... Read More

Advertisements