Found 10711 Articles for Web Development

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

Shubham Vora
Updated on 20-Jul-2022 08:17:30

4K+ 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() and Math.round() MethodsUsing the parseInt() MethodUsing the Bitwise ... Read More

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

varma
Updated on 12-Sep-2019 08:04:37

308 Views

In JavaScript, Semicolons are optional. Simple statements in JavaScript are generally followed by a semicolon character, just as they are in C, C++, and Java. JavaScript, however, allows you to omit this semicolon if each of your statements is placed on a separate line. It is a good programming practice to use semicolons.In JavaScript, use a semi-colon after a statement. Let’s see an example of a variable assignment:var s = function() {    alert("Hello World!"); };However, semicolons aren’t necessary for the following function declarations:function() {    alert("Hello World!"); };

Do we need to use semicolons in JavaScript?

varun
Updated on 12-Sep-2019 08:05:42

125 Views

In JavaScript, Semicolons are optional. Simple statements in JavaScript are generally followed by a semicolon character, just as they are in C, C++, and Java. JavaScript, however, allows you to omit this semicolon if each of your statements is placed on a separate line. It is a good programming practice to use semicolons.For example, the following code could be written without semicolon.     But when formatted in a single line as follows, you must use semicolons −    

What Are Whitespace and Line Breaks in JavaScript?

usharani
Updated on 12-Sep-2019 08:07:03

1K+ Views

JavaScript ignores spaces, tabs, and newlines that appear in JavaScript programs. You can use spaces, tabs, and newlines freely in your program and you are free to format and indent your programs in a neat and consistent way that makes the code easy to read and understand.JavaScript ignores whitespaces. For example, the following are same:var employee = "Amit"; var employee="Amit";Line breaks in JavaScript:           Line-break in an alert box. Click below button.       Click    

How can I replace newlines with spaces in JavaScript?

Shubham Vora
Updated on 12-Jul-2022 14:15:16

4K+ Views

This tutorial teaches us to replace newlines with spaces in JavaScript. Often, programmers find unusual line breaks in the string, and the random line breaks look weird when we render them on the webpage using JavaScript.So, the solution is that programmers just need to remove the line breaks and join the string with the space or other characters. Here, we have different approaches to solving this problem, and we will use the regular expression with the replace() method to remove the unusual line breaks.Using the replace() MethodUsing the split() and join() MethodsUsing the replace() MethodIn this approach, we will use ... Read More

What is the difference between a method and a function?

seetha
Updated on 30-Sep-2019 06:57:27

6K+ Views

Method and a function are the same, with different terms. A method is a procedure or function in object-oriented programming.A function is a group of reusable code which can be called anywhere in your program. This eliminates the need for writing the same code again and again. It helps programmers in writing modular codes.The following is the syntax of a JavaScript function:     Here’s an example:    

How can I remove the (//) blocks; tags inside a script element in Javascript?

Saurabh Jaiswal
Updated on 11-Aug-2022 11:30:45

584 Views

CDATA, the short form of Character Data is a block of code that has been written to prevent parsing by the parser. Sometimes our data includes predefined characters like “ Syntax str.replace("regex", "") Here str is the string from which you want to remove the CDATA, regex is the regular expression to find the block data. Example In the below program example, we remove the CDATA blocks and tags inside a script element using the String replace() method. We pass the regex defined above as an argument to the replace() method and the second argument is an empty string. ... Read More

Are HTML comments inside script tags a best practice?

Bhanu Priya
Updated on 09-Nov-2023 14:29:04

1K+ Views

Before trying to understanding whether HTML comments inside script tags is best practice or not, let us discuss about how to write comments in HTML, what are the different ways to comment in HTML? Generally, comments are helpful to understand the statement, it leaves remainders and provide explanations. It also helps in disabling the statement when we are testing or working on new feature. Syntax Following is the syntax for comment representation − Let us see different ways to represent comments in a program − Inserting a single-line comment The single line comment is applied to single ... Read More

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

Giri Raju
Updated on 02-Jan-2020 09:41:54

142 Views

The full form of ECMA is European Computer Manufacturer's Association. ECMAScript is a Standard for scripting languages such as JavaScript, JScript, etc. It is a trademark scripting language specification. JavaScript is a language based on ECMAScript. A standard for scripting languages like JavaScript, JScript is ECMAScript. JavaScript is considered as one of the most popular implementations of ECMAScript.ECMAScript 6 is working fine on web browsers like Chrome, Microsoft Edge, Safari, etc:90% compatibility – Chrome 80% compatibility - Microsoft Edge54% compatibility – SafariUse ES6 using Babale pre-processor, which cross-compile JavaScript back to ECMAScript 5 compatible code.Here are features of ECMAScript 6:Arrow FunctionsDeclare ... Read More

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

varma
Updated on 02-Jan-2020 09:03:25

184 Views

ECMAScript is a standard for JavaScript implementation. You cannot run or download ECMAScript. JavaScript 2.0 conforms to Edition 5 of the ECMAScript standard, and the difference between the two is minor.The 8th edition, known as ECMAScript 2017, came in June 2017. ECMAScript is a Standard for scripting languages such as JavaScript, JScript, etc. It is a trademark scripting language specification. JavaScript is a language based on ECMAScript. A standard for scripting languages like JavaScript, JScript is ECMAScript. JavaScript is considered as one of the most popular implementations of ECMAScript.The ECMA-262 Specification defined a standard version of the core JavaScript language.JavaScript ... Read More

Advertisements