Found 6685 Articles for Javascript

What are JavaScript Native Objects?

Shubham Vora
Updated on 15-Nov-2022 10:44:56

3K+ Views

In this tutorial, we will learn about native objects in JavaScript. Native JavaScript objects are regular JavaScript objects offered by JavaScript itself. Inbuilt objects, pre-defined objects, and global objects are other names. No matter the computer or environment, all users have access to these objects, and they function similarly. They may be used as both constructors (like String(), Array(), and Object()) and primitive values since their functions are unaffected by changes to the machine or environment. An object in an ECMAScript implementation whose semantics are entirely determined by this specification as opposed to the host environment. Native objects are additionally ... Read More

How to simulate a keypress event in JavaScript?

Abhishek Kumar
Updated on 21-Sep-2022 08:05:35

6K+ Views

We use event handlers to simulate keypress events in JavaScript. An event in JavaScript, as the name suggests, refers to actions taken by the browser or user. An event handler is a utility that JavaScript provides, that lets the programmer implement the correct course of response to those events. We will be using the jQuery library to simulate keypress events in JavaScript. It is a library for JavaScript to traverse HTML documents as well as manipulate them, create animations, and much more. One such feature is event handling that we will be using. Event An Event is a change that ... Read More

How to use the 'with' keyword in JavaScript?

Nitya Raut
Updated on 17-Jun-2020 06:14:29

5K+ Views

The with keyword is used as a kind of shorthand for referencing an object's properties or methods.The object specified as an argument to with becomes the default object for the duration of the block that follows. The properties and methods for the object can be used without naming the object.SyntaxThe syntax for with object is as follows −with (object){    properties used without the object name and dot }ExampleYou can try to learn the following code to learn how to implement with keyword −Live Demo           User-defined objects               ... Read More

What are secured cookies in JavaScript?

Daniol Thomas
Updated on 30-Jul-2019 22:30:21

2K+ Views

A secured cookie is a cookie that works with HTTP/HTTPS, known as a httpOnly cookie. These cookies are only used for HTTP requests, so unethical access though scripting is not possible. Therefore, cross-site scripting can be stopped, which in turn stops attacks.The secure attribute is always activated for secured cookies, so it is transmitted with encrypted connections, without any hassles and security issues. The httpOnly flag does not give cookie access to JavaScript or any non-HTTP methods. This is situated in the secure cookie header.The secure attribute and httpOnly flag ensure that the browser does not allow malicious scripts to ... Read More

How can I store JavaScript objects in cookies?

Shubham Vora
Updated on 09-Aug-2022 14:23:20

10K+ Views

This tutorial will teach us to store JavaScript objects into the cookies. The cookies are the information of website visitors stored in the text files. There is a particular mechanism to store the cookies of users' browsers. When new visitors visit the website, the server generates the text and sends it to the user. After that, when users allow access to the web page to retrieve the cookies, the server stores all user information in the text files. Cookies store the user’s search history or other information for a better experience. For example, Google stores the user’s search history to ... Read More

How to create JavaScript objects using object() constructor?

Jennifer Nicholas
Updated on 16-Jun-2020 13:53:02

283 Views

A constructor is a function that creates and initializes an object. JavaScript provides a special constructor function called Object() to build the object. The return value of the Object() constructor is assigned to a variable.The variable contains a reference to the new object. The properties assigned to the object are not variables and are not defined with the var keyword.ExampleYou can try to run the following code to learn how to work with JavaScript objects with object() constructor −Live Demo           User-defined objects                var book = new Object(); ... Read More

How to detect all active JavaScript event handlers?

Nishtha Thakur
Updated on 09-Jan-2020 10:20:19

587 Views

The simplest solution is to use jQuery to detect all active JavaScript event handlers.ExampleYou can try to run the following code to detect active event handlersLive Demo                          var myEvent = $("#demo");          myEvent.mouseover(function() {});          $.each(myEvent.data("events"), function(i, e) {             alert(i);          });                     Demo Text    

What is the difference between new operator and object() constructor in JavaScript?

Rishi Rathor
Updated on 17-Jun-2020 06:09:54

935 Views

The new operatorThe new operator is used to create an instance of an object. To create an object, the new operator is followed by the constructor method.In the following example, the constructor methods are Object(), Array(), and Date(). These constructors are built-in JavaScript functions.var department = new Object(); var books = new Array("C++", "Perl", "Java"); var day = new Date(“December 1, 2017");The object() constructorA constructor is a function that creates and initializes an object. JavaScript provides a special constructor function called Object() to build the object. The return value of the Object() constructor is assigned to a variable.The variable contains ... Read More

What are the differences between JavaScript and PHP cookies?

Anvi Jain
Updated on 03-Oct-2019 08:09:22

576 Views

JavaScript CookiesUsing JavaScript cookies is the most efficient method of remembering and tracking preferences, purchases, commissions, and other information required for better visitor experience or site statistics.PHP CookiesCookies are text files stored on the client computer and they are kept for tracking purpose. PHP transparently supports HTTP cookies.How JavaScript cookies work?Your server sends some data to the visitor's browser in the form of a cookie. The browser may accept the cookie. If it does, it is stored as a plain text record on the visitor's hard drive. Now, when the visitor arrives at another page on your site, the browser ... Read More

How to define methods for an Object in JavaScript?

Nancy Den
Updated on 03-Oct-2019 08:07:09

83 Views

Methods are the functions that let the object do something or let something is done to it. There is a small difference between a function and a method – at a function is a standalone unit of statements and a method is attached to an object and can be referenced by this keyword.Methods are used for everything from displaying the contents of the object to the screen to performing complex mathematical operations on a group of local properties and parameters. Here’s an example showing how to use the write() method of the document object to write any content on the document.document.write("This ... Read More

Advertisements