Javascript Articles - Page 592 of 671

How to define a Regular Expression in JavaScript?

Sravani S
Updated on 19-May-2020 11:07:45

179 Views

A regular expression is an object that describes a pattern of characters.The JavaScript RegExp class represents regular expressions, and both String and RegExp define methods that use regular expressions to perform powerful pattern-matching and search-and-replace functions on the text. A regular expression could be defined with the RegExp () constructor, as follows −var pattern = new RegExp(pattern, attributes); or var pattern = /pattern/attributes;The following are the parameters −pattern − A string that specifies the pattern of the regular expression or another regular expression.attributes − An optional string containing any of the "g", "i", and "m" attributes that specify ... Read More

How to convert a date to a string using the universal time convention?

Nancy Den
Updated on 23-Jun-2020 07:59:39

168 Views

To convert a date to a string using the universal time convention, use the toUTCString() method. It returns converted the date to a string, using the universal time convention.ExampleYou can try to run the following code to learn how to convert a date to a string using UTC −           JavaScript toUTCString Method                        var dateobject = new Date(2018, 0, 15, 14, 39, 7);          document.write( dateobject.toUTCString() );          

Which event occurs in JavaScript when a dragged element is dropped?

Swarali Sree
Updated on 23-Jun-2020 08:05:55

162 Views

The ondrop event triggers when a dragged element is dropped on the target. You can try to run the following code to learn how to implement ondrop event in JavaScript −ExampleLive Demo                    .drag {             float: left;             width: 100px;             height: 35px;             border: 2px dashed #876587;             margin: 15px;             padding: 10px;          } ... Read More

How to return the "time" portion of the Date as a human-readable string.

Sai Nath
Updated on 23-Jun-2020 08:00:07

110 Views

To return the “time” portion of the Date as a human-readable string, use the toTimeString() method in JavaScript. This method returns the time portion of a Date object in the human-readable form.ExampleYou need to run the following code to return only the time portion of a Date −           JavaScript toTimeString Method                        var dateobject = new Date(2018, 0, 1, 14, 39, 7);          document.write( dateobject.toTimeString() );          

What is the role of the window.history object in JavaScript?

Paul Richard
Updated on 23-Jun-2020 08:00:51

232 Views

The window.history object is used to go back or to the next page of the web browser. It has the browser's history and comes with the following two methods −history.back − Go to previous URLhistory.next − Go to next URLExampleYou can try to run the following code to learn how to work with window.history object in JavaScript −Live Demo                    function backPage() {             window.history.back()          }          function nextPage() {             window.history.next()          }                      

How to load the next URL in the history list in JavaScript?

Shubham Vora
Updated on 14-Sep-2022 13:31:40

794 Views

In this tutorial, we will learn to load the next page in the history list in JavaScript. The Window object in JavaScript accesses the window in the browser. This object contains many properties and methods required to do the tasks. The Window object also retrieves the information from the browser window. There is a history stack in every browser that saves the pages visited by the user. To access this history stack, we can use the history object that is the property of the Window object. By accessing the history from the browser, we can go to the next or ... Read More

What is the role of ignoring Case RegExp property in JavaScript?

Abhinanda Shri
Updated on 19-May-2020 11:06:36

95 Views

ignoreCase is a read-only boolean property of RegExp objects. It specifies whether a particular regular expression performs case-insensitive matching, i.e., whether it was created with the "i" attribute.ExampleYou can try to run the following code to learn how to work with Ignore Case RegExp property in JavaScript.           JavaScript RegExp ignoreCase Property                        var re = new RegExp( "string" );          if ( re.ignoreCase ) {             document.write("Test1-ignoreCase property is set");          } ... Read More

What is the role of source RegExp property in JavaScript?

Akshaya Akki
Updated on 23-Jun-2020 08:02:06

162 Views

The source RegExp property in JavaScript is a read-only string property of RegExp objects. It contains the text of the RegExp pattern. This text does not include the delimiting slashes used in regular-expression literals, and it does not include the "g", "i", and "m" attributes.ExampleYou can try to run the following code to learn how to implement source RegExp property in JavaScript −           JavaScript RegExp source Property                        var str = "JavaScript is an interesting scripting language";          var re = new RegExp( "script", "g" );          re.test(str);                    document.write("The regular expression is : " + re.source);          

What is availHeight property in JavaScript?

karthikeya Boyini
Updated on 23-Jun-2020 08:03:15

89 Views

Use the screen.availHeight property to return the width of the user’s screen. The result will be in pixels and Taskbar feature won’t be included.ExampleYou can try to run the following code to learn how to work with the screen.availHeight property in JavaScript −Live Demo                    document.write("Height of the screen: "+screen.availHeight);          

What is the role of pageYOffset property?

Fendadis John
Updated on 19-May-2020 10:59:13

341 Views

If you want to get the pixels of the document scrolled to from the upper left corner of the window, then use the pageXoffset and pageYoffset property. Use pageYoffset for vertical pixels.ExampleYou can try to run the following code to learn how to work with pageYOffset property in JavaScript.Live Demo                    div {             background-color: green;             height: 1500px;             width: 1500px;          }                              function scrollFunc() {             window.scrollBy(200, 200);             alert("Vertical: " + window.pageYOffset);          }             Scroll                      

Advertisements