Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Javascript Articles
Page 518 of 534
Why JavaScript Data Types are Dynamic?
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 MoreWhat are runtime errors in JavaScript?
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 MoreHow to define integer constants in JavaScript?
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 MoreHow to generate Prime Numbers in JavaScript?
To generate prime numbers in JavaScript, you can try to run the following code Example JavaScript Prime for (var limit = 1; limit
Read MoreWhat is the difference between parseInt(string) and Number(string) in JavaScript?
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 MoreHow to integrate Google AdSense into your webpage?
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 MoreHow to create JavaScript alert with 3 buttons (Yes, No and Cancel)?
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 MoreHow to deal with floating point number precision in JavaScript?
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 MoreHow to list down all the cookies by name using JavaScript?
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 MoreHow to set src to the img tag in HTML from another domain?
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