In JavaScript, the Boolean object is a wrapper around a primitive boolean value (either true or false). The Boolean object provides methods and properties to manipulate and work with boolean values. Here’s an example of creating a Boolean object: var boolObj = new Boolean(true); console.log(boolObj); // logs: Boolean {true} In this example, we create a …
Category: JavaScript
JavaScript The Number Object
In JavaScript, the Number object is a built-in object that represents a numerical value. It can be used to perform mathematical operations, and provides several methods for formatting and manipulating numbers. Here are some basic examples of using the Number object: let num = new Number(10); // creates a number object with a value of …
JavaScript Objects Overview
JavaScript objects are one of the fundamental data types in the language, and are used extensively in web development. They allow developers to store and organize related data and functions, and can be created and manipulated dynamically at runtime. In JavaScript, an object is essentially a collection of key-value pairs, where the keys are strings …
JavaScript Page Printing
To print a web page using JavaScript, you can use the window.print() method. This method will open the print dialog box and allow the user to choose their print settings before printing the page. Here’s an example of how to use window.print(): // Wait for the page to finish loading window.onload = function() { // …
JavaScript Void Keyword
In JavaScript, the void keyword is an operator that takes an expression and evaluates it, but then always returns undefined. It is often used in event handlers for hyperlinks and buttons to prevent the default behavior of navigating to a new page or submitting a form. Here is an example of using the void operator …
JavaScript Dialog Boxes
JavaScript provides three types of dialog boxes: alert, prompt, and confirm. These dialog boxes can be used to interact with users and get their input. Example: alert(“Hello World!”); Example: let name = prompt(“What is your name?”); alert(“Hello ” + name + “!”); Example: let result = confirm(“Do you want to proceed?”); if (result == true) …
JavaScript Page Redirection
In JavaScript, you can use the window.location object to redirect to another page. Here’s an example: // Redirect to a new page window.location.href = “https://example.com”; // Redirect to a new page without keeping the current page in the session history window.location.replace(“https://example.com”); The window.location.href property sets the URL of the current page to the specified URL, …
JavaScript and Cookies
JavaScript and cookies are two separate technologies, but they can work together to enhance the functionality and user experience of a website. JavaScript is a programming language used to create interactive and dynamic web content. It is commonly used for tasks such as form validation, animations, and interactive menus. JavaScript can also interact with cookies. …
JavaScript Events
JavaScript events are actions or occurrences that happen within a web page, such as a user clicking a button or a web page finishing loading. JavaScript events allow you to respond to these actions or occurrences and execute specific code or functions when they occur. There are many types of events in JavaScript, including: You …
JavaScript Functions
JavaScript functions are blocks of code that can be defined and executed at a later time. They are a fundamental part of JavaScript programming and allow for the creation of reusable code that can be used multiple times in a program. Functions in JavaScript can be defined using the “function” keyword, followed by the name …