Javascript Articles

Page 518 of 534

Why JavaScript Data Types are Dynamic?

Sravani S
Sravani S
Updated on 16-Jan-2020 252 Views

JavaScript also has dynamic types. That would mean the same variable used for holding different data types in JavaScript.Example                    var val;          val = "Amit";          document.write("String: "+val);          val = 20;          document.write("Number: "+val);          val = 40.90;          document.write("Number with decimals: "+val);                  

Read More

What are runtime errors in JavaScript?

Rishi Rathor
Rishi Rathor
Updated on 16-Jan-2020 318 Views

There are three types of errors in programming: (a) Syntax Errors, (b) Runtime Errors, and (c) Logical Errors. Runtime errors, also called exceptions, occur during execution (after compilation/interpretation). For example, the following line causes a runtime error because here the syntax is correct, but at runtime, it is trying to call a method that does not exist.     Exceptions also affect the thread in which they occur, allowing other JavaScript threads to continue normal execution.

Read More

How to define integer constants in JavaScript?

V Jyothi
V Jyothi
Updated on 13-Jan-2020 1K+ Views

ECMAScript allows usage of const to define constants in JavaScript. To define integer constants in JavaScript, use the const,const MY_VAL = 5; // This will throw an error MY_VAL = 10;As shown above, MY_VAL is a constant and value 5 is assigned. On assigning, another value to a constant variable shows an error.Using const will not allow you to reassign any value to MY_VAL again. If you will assign a new value to a constant, then it would lead to an error.

Read More

How to generate Prime Numbers in JavaScript?

Ayyan
Ayyan
Updated on 13-Jan-2020 3K+ Views

To generate prime numbers in JavaScript, you can try to run the following code Example        JavaScript Prime                  for (var limit = 1; limit

Read More

What is the difference between parseInt(string) and Number(string) in JavaScript?

V Jyothi
V Jyothi
Updated on 13-Jan-2020 319 Views

parseInt(string)The parseInt() method parses up to the first non-digit and returns the parsed value.  For example, the following returns 765:parseInt("765world")Let’s take another example. The following returns 50:parseInt(‘50px”);Number(string)Number() converts the string into a number, which can also be a float BTW.For example, the following returns NaN:Number(“765world”)The following returns NaN:Number(“50px”);

Read More

How to integrate Google AdSense into your webpage?

Anjana
Anjana
Updated on 10-Jan-2020 504 Views

If your website is having a sufficient content and a good number of page views, then start adding some advertisements to earn money. Google AdSense is a free and easy way to earn money by placing ads on your website.Integrating Google AdSense on a website is quite easy. Let’s see the steps:Go to the official website and SIGN IN with the Google Account, which you want to use for AdSense.Setup the account will all the details i.e. website information, content language, etc.Read the Google AdSense Terms and Conditions and follow the Google rules. Also, read the Google Program Policies and do ...

Read More

How to create JavaScript alert with 3 buttons (Yes, No and Cancel)?

Prabhas
Prabhas
Updated on 10-Jan-2020 4K+ Views

The standard JavaScript alert box won’t work if you want to customize it. For that, we have a custom alert box, which we’re creating using jQuery and styled with CSS.ExampleYou can try to run the following code to create an alert box with 3 buttons i.e Yes, No and Cancel.                          function functionConfirm(msg, myYes, myNo, cancel) {             var confirmBox = $("#confirm");             confirmBox.find(".message").text(msg);             confirmBox.find(".yes, .no, .cancel").unbind().click(function() {     ...

Read More

How to deal with floating point number precision in JavaScript?

varma
varma
Updated on 10-Jan-2020 971 Views

To handle floating point number precision in JavaScript, use the toPrecision() method. It helps to format a number to a length you can specify. Example               var num = 28.6754;       document.write(num.toPrecision(3));       document.write("<br>"+num.toPrecision(2));       document.write("<br>"+num.toPrecision(5));         Output 28.7 29 28.675

Read More

How to list down all the cookies by name using JavaScript?

Rishi Rathor
Rishi Rathor
Updated on 09-Jan-2020 309 Views

To lists down all the cookies by name, use the cookies pairs in an array. After that, you need to get the key value pair out of this array. Example You can try to run the following code to list all the cookies                                                      click the following button and see the result:                      

Read More

How to set src to the img tag in HTML from another domain?

Akshaya Akki
Akshaya Akki
Updated on 09-Jan-2020 3K+ Views

To use an image on a webpage, use the tag. The tag allows you to add image source, alt, width, height, etc. The src is to add the image URL. The alt is the alternate text attribute, which is text that is visible when the image fails to load. With HTML, add the image source as another domain URL. For that, add the src attribute as a link to another domain. The following are the attributes: Sr.No. Attribute & Description 1 altThe alternate text for the image 2 heightThe height ...

Read More
Showing 5171–5180 of 5,339 articles
« Prev 1 516 517 518 519 520 534 Next »
Advertisements