Programming Scripts Articles - Page 43 of 37

How can I write a script to use either W3C DOM or IE 4 DOM depending on their availability?

Abhinanda Shri
Updated on 23-Jun-2020 07:25:37

166 Views

If you want to write a script with the flexibility to use either W3C DOM or IE 4 DOM depending on their availability, then you can use a capability-testing approach that first checks for the existence of a method or property to determine whether the browser has the capability you desire.The following is the code snippet showing the same −if (document.getElementById) {    // If the W3C method exists, use it } else if (document.all) {    // If the all[] array exists, use it } else {    // Otherwise use the legacy DOM }

What is the role of throw statement in JavaScript?

Jennifer Nicholas
Updated on 23-Jun-2020 07:25:09

216 Views

Use the throw statement to raise your built-in exceptions or your customized exceptions. Later these exceptions can be captured and you can take appropriate action.ExampleYou can try to run the following code to implement throw statement −                                         Click the following to see the result:                          

What is the difference between setTimeout() and setInterval() in JavaScript?

Rishi Rathor
Updated on 24-Nov-2023 00:58:53

2K+ Views

setTimeout() function setTimeout( function, duration) − This function calls function after duration milliseconds from now. This goes for one execution. Let’s see an example − It waits for 2000 milliseconds, and then runs the callback function alert(‘Hello’) − setTimeout(function() { alert('Hello');}, 2000); setInterval() function setInterval(function, duration) − This function calls function after every duration milliseconds. This goes for unlimited times. Let’s see an example − It triggers the alert(‘Hello’) after every 2000 milliseconds, not only once. setInterval(function() { alert('Hello');}, 2000);

With JavaScript how can I find the name of the web browser, with version?

Abhinaya
Updated on 23-Jun-2020 07:01:42

370 Views

To find the name of the web browser, with version, you need to try the following code −Example           Browser Detection Example                                  

What are different Navigator properties I can use on my web page?

Daniol Thomas
Updated on 23-Jun-2020 07:02:17

194 Views

can use several Navigator related properties in your Web page. The following are the properties −Sr.NoProperty & Description1appCodeNameThis property is a string that contains the code name of the browser, Netscape for Netscape and Microsoft Internet Explorer for Internet Explorer.2appVersionThis property is a string that contains the version of the browser as well as other useful information such as its language and compatibility.3languageThis property contains the two-letter abbreviation for the language that is used by the browser. Netscape only.4mimTypes[]This property is an array that contains all MIME types supported by the client. Netscape only.5platform[]This property is a string that contains ... Read More

How can I add debugging code to my JavaScript?

Krantik Chavan
Updated on 17-Jan-2020 11:06:09

246 Views

To add debugging code to JavaScript, use the alert() or document.write() methods in your program. For example,var debugging = true; var whichImage = "widget"; if( debugging ) alert( "Calls swapImage() with argument: " + whichImage ); var swapStatus = swapImage( whichImage ); if( debugging ) alert( "Exits swapImage() with swapStatus=" + swapStatus );Examine the content and order of the alert() as they appear, you can examine the health of your program very easily.

How to reduce the number of errors in scripts?

Ramu Prasad
Updated on 23-Jun-2020 07:03:36

267 Views

To reduce the number of errors in scripts, follow the below-given tips −Use plenty of comments. Comments enable you to explain why you wrote the script the way you did and to explain particularly difficult sections of code.Always use indentation to make your code easy to read. Indenting statements also make it easier for you to match up the beginning and ending tags, curly braces, and other HTML and script elements.Write modular code. Whenever possible, group your statements into functions. Functions let you group related statements, and test and reuse portions of code with minimal effort.Be consistent in the way you ... Read More

What is the difference between #define and const Keyword in C++?

Akansha Kumari
Updated on 28-May-2025 19:04:05

530 Views

In C++, both #define and const are used to define constants in a program. The #define is a preprocessor directive that creates macros with their fixed values whereas const is a keyword which declare value of variable as constant, meaning its value cannot be changed after intialization. Therefore they have different use cases in different scenarios. In this article, we will learn the differences between these two in detail. #define in C++ The #define is a preprocessor directive that is used to define or assign macros ( name or string ) with a constant value. So wherever the macro occurs ... Read More

How to subtract Python timedelta from date in Python?

Rajendra Dharmkar
Updated on 28-Aug-2025 12:15:29

11K+ Views

The Python datetime module provides various ways for manipulating dates and times. One of its key features is the timedelta object, which represents duration and also the difference between two dates or times. Subtracting a specific amount of time from a date can be done using timedelta. For example, if we want to find the date a day before today, then we create a timedelta object with days=1 and then subtract it from the current date. Subtracting One Day from Today's Date Using timedelta The basic use case is subtracting a single day from today's date. This can be done ... Read More

Advertisements