Javascript Articles

Page 522 of 534

How do I convert a float number to a whole number in JavaScript?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 6K+ Views

In this tutorial, we will learn to convert a float number to a whole number in JavaScript. The whole number is the number that doesn't contain the fractional part. For example, 5.22 is the float number containing the fractional part, and the whole number doesn't contain a decimal part. So, our goal in this tutorial is to remove the fractional part from the number. We can have various methods to cut out the decimal part from the float number to make it whole, and some of them we have discussed here. Using the Math.trunc() ...

Read More

When should I use a semicolon after curly braces in JavaScript?

varma
varma
Updated on 15-Mar-2026 468 Views

In JavaScript, semicolons are optional in many cases due to Automatic Semicolon Insertion (ASI). However, understanding when to use semicolons after curly braces is crucial for writing clean, predictable code. When Semicolons Are Required After Curly Braces Use semicolons after curly braces when they end a statement, not a declaration. Here are the key cases: Function Expressions Function expressions are statements that need semicolons: // Function expression - needs semicolon var greet = function() { alert("Hello World!"); }; // Arrow function expression - needs semicolon const ...

Read More

Do we need to use semicolons in JavaScript?

varun
varun
Updated on 15-Mar-2026 286 Views

In JavaScript, semicolons are optional in many cases due to Automatic Semicolon Insertion (ASI). While JavaScript can automatically insert semicolons at line breaks, it's considered good practice to include them explicitly for better code clarity and to avoid potential issues. How Automatic Semicolon Insertion Works JavaScript automatically inserts semicolons at the end of statements when certain conditions are met, primarily at line breaks where the code would otherwise be syntactically invalid. // Without semicolons - ASI will insert them let a = 5 let b = 10 console.log(a + b) 15 ...

Read More

What Are Whitespace and Line Breaks in JavaScript?

Alshifa Hasnain
Alshifa Hasnain
Updated on 15-Mar-2026 2K+ Views

JavaScript like other programming languages permits whitespace and line breaks to make code more readable. While JavaScript generally ignores whitespace, understanding how it handles whitespace and line breaks is crucial for writing clean, maintainable code. What is Whitespace in JavaScript? Whitespace in JavaScript includes spaces, tabs, and newlines. JavaScript's engine ignores excess whitespace, meaning that adding spaces between variables, operators, or keywords doesn't affect code execution. This allows developers to format their code for better readability. Example: Whitespace Ignored The following two code snippets are functionally identical: // With spaces (readable) var employee = ...

Read More

How can I replace newlines with spaces in JavaScript?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 5K+ Views

This tutorial teaches us to replace newlines with spaces in JavaScript. Often, programmers find unusual line breaks in strings, and random line breaks look weird when rendered on webpages using JavaScript. The solution is to remove line breaks and join the string with spaces or other characters. We have different approaches to solve this problem using regular expressions with the replace() method or string manipulation methods. Using the replace() Method ...

Read More

What is the difference between a method and a function?

Alshifa Hasnain
Alshifa Hasnain
Updated on 15-Mar-2026 7K+ Views

In this article, we will learn about the difference between a method and a function in JavaScript. While both execute code blocks, the key difference is that a function is standalone code, while a method is a function that belongs to an object. What is a Function? A function is a reusable block of code that can be called anywhere in your program. Functions help create modular code by eliminating repetition. JavaScript functions can be defined using function expressions, arrow functions, or the function keyword. Syntax function functionName(parameter1, parameter2) { ...

Read More

How can I remove the (//<![CDATA[ , //]]>) blocks; tags inside a script element in Javascript?

Saurabh Jaiswal
Saurabh Jaiswal
Updated on 15-Mar-2026 942 Views

CDATA, the short form of Character Data, is a block of code that prevents parsing by the XML/HTML parser. Sometimes our data includes predefined characters like "" + cleanedContent + ""; Using replaceAll() Method (Tags Only) The replaceAll() method can remove only the CDATA tags () while preserving the content inside. This approach is useful when you want to keep the JavaScript code but remove the CDATA wrapper. Syntax string.replaceAll("", "") Example In this example, we remove only the CDATA tags while keeping the ...

Read More

What ECMAScript 6 features can I currently use in web browsers?

Giri Raju
Giri Raju
Updated on 15-Mar-2026 284 Views

ECMAScript 6 (ES6), also known as ECMAScript 2015, introduced many powerful features to JavaScript. Most modern web browsers now support the majority of ES6 features, making them safe to use in production applications. Browser Compatibility Current ES6 browser support varies across different browsers: Browser ES6 Support Recommended Version Chrome 97%+ 51+ Firefox 97%+ 54+ Safari 95%+ 10+ Edge 96%+ 15+ Core ES6 Features You Can Use Today Arrow Functions Arrow functions provide a concise syntax for writing functions: // Traditional ...

Read More

Does a real ECMAScript implementation exist, or is it just a spec?

varma
varma
Updated on 15-Mar-2026 352 Views

ECMAScript is a standardization specification, not an actual programming language implementation that you can download and run. Think of it as a blueprint that defines how JavaScript engines should work. What is ECMAScript? ECMAScript (standardized as ECMA-262) is a scripting language specification created to standardize JavaScript. It defines the syntax, types, statements, keywords, and built-in objects that JavaScript implementations should provide. ECMAScript vs JavaScript - Key Differences ECMAScript JavaScript Specification/Standard Implementation of the specification Defines language features Actual runnable code Published by ECMA International Implemented by browser engines ...

Read More

JavaScript closures vs. anonymous functions

Alshifa Hasnain
Alshifa Hasnain
Updated on 15-Mar-2026 907 Views

In this article, we will learn about JavaScript's closures and anonymous functions. JavaScript is a powerful language that allows developers to write expressive and concise code. Two concepts that often confuse beginners are closures and anonymous functions. While they share some similarities, they serve different purposes and function differently in JavaScript. What are Anonymous Functions? An anonymous function is simply a function without a name. Anonymous, as the name suggests, allows the creation of a function without any name identifier. It can be used as an argument to other functions, assigned to a variable, or immediately invoked. They ...

Read More
Showing 5211–5220 of 5,340 articles
« Prev 1 520 521 522 523 524 534 Next »
Advertisements