Home » Programming » Javascript

How to Get the Length of an Array in JavaScript [Examples]

JavaScript Array Length

This article will show you how to get the length of an array in JavaScript, as well as provide some code examples. JavaScript is one of the most popular programming languages. From humble origins as a webpage scripting language for animating menus and displaying pop-up ads, it is now a full-blown ecosystem that you can use to build cross-platform mobile apps, web pages, server processes, and even games. JavaScript Arrays Arrays are a vital building block for any program, even simple ones. An array is a … Read more

Home » Programming » Javascript

How To Compare Arrays in JavaScript, With Examples

Compare Arrays in JavaScript

This article will show you how to compare arrays in JavaScript and provides some ready-to-use functions to do so. We’ve already covered a bit on how to use arrays in JavaScript: Looping over Array using JavaScript forEach(), With Examples Array slice() Method in JavaScript, with Examples() Check Array Contains a Value in JavaScript, with Examples Removing an Element From an Array in JavaScript, with Examples What is an Array? An array is a type of JavaScript variable that can hold other variables, or references to … Read more

Home » Programming » Javascript

JavaScript instanceof Operator – What it Does, How to Use It

JavaScript instanceof Operator

This article will explain what the JavaScript instanceof operator does and how it can be used. Examples provided. What does instanceof do? The instanceof operator returns TRUE or FALSE depending on whether a given value or variable is of a certain type or class – it checks whether a value is an instance of a given object class or type. The purpose of instanceof may seem confusing – you already have typeof, so what do you need instanceof for? typeof will simply return a string containing the name of the type or class of the variable. In contrast, instanceof will return a … Read more

Home » Programming » Javascript

JavaScript onclick() Events – Tutorial, With Examples

JavaScript onclick() Tutorial

JavaScript adds interactivity to web pages. This article shows you how to trigger JavaScript functions when an HTML element is clicked using onclick() events and attributes. Code examples included. JavaScript Events An event in JavaScript simply means that something has happened. The mouse has moved, or a key has been pressed, and JavaScript has been notified by the raising of an event. onclick Event When the user clicks on something, the onclick event is raised, allowing you to trigger some JavaScript code when an element is clicked. … Read more

Home » Programming » Javascript

JavaScript vs Java – What’s the Difference Which to Use in 2021?

JavaScript vs Java

Here’s a clear article on what makes Java and JavaScript different – and some information to help you make the choice on which to learn and use for your projects in 2021. First up, it’s important to clarify that JavaScript and Java are not the same things! They just have similar names. It’s stupid, and they should have called JavaScript something else (and tried to re-badge it ECMA Script, which is also a terrible name), but the JavaScript name stuck. Now we’re all stuck with two different programming languages … Read more

Home » Programming » Javascript

Using The isNaN() Function in JavaScript, With Examples

JavaScript isNan()

isNaN() is a JavaScript function that will tell you whether a value is equal to NaN – or Not a Number. It can be used to determine whether the result of a mathematical operation is valid or not. Here’s how to use it. What is NaN? NaN is a special value that means Not a Number. It means that a value that should be a number could not be parsed as a number. Any mathematical operation between any other value and NaN will result in NaN. It usually means something has … Read more

Home » Programming » Javascript

JavaScript Callback Functions How-To, With Examples

JavaScript Callbacks

This article will explain callback functions in JavaScript – what they are, why they’re used, and how to use them. What is a Callback in the JavaScript Programming Language? A callback function is a function that is passed as a parameter to another function to be executed from within the second function. What are Callbacks Useful For? Callback functions are usually used to execute a function when another has been completed. This allows for easy code- reuse. A single function that accepts a callback can be … Read more

Home » Programming » Javascript

jQuery vs JavaScript – Differences? Which is Better?

jQuery vs JavaScript

This article will explain what JavaScript and jQuery are, how they differ, and how/why they should be used. What is JavaScript JavaScript began life in the mid-1990s as a scripting language for adding interactivity to web pages. Over time it has been developed into a full-featured programming language, which can even be run outside the web browser (more detail on this in our Node.js article). You can also see our article outlining the differences between JavaScript and Typescript here. What is jQuery? jQuery is a library written in JavaScript. … Read more

Home » Programming » Javascript

How to Refresh the Page in JavaScript using location.reload(), With Examples

JavaScript Refresh Page

Here’s a short guide to refreshing a webpage with JavaScript, with examples. There are over 500 ways to trigger a page reload using JavaScript. All but one are unofficial or are the side effect of another behavior. Here’s how to do it properly. Using location.reload() Simply call: location.reload() …anywhere in your code to trigger a page reload. It’s that easy. What about window.location.reload() ? You may see some use: window.location.reload() This is exactly the same as using location.reload() – the window object in JavaScript is the global context, so there’s usually no … Read more

Home » Programming » Javascript

Compare JavaScript Dates (Day/Minute/Hour/Before/After), With Examples

JavaScript Compare Dates

Following on from our article on adding and subtracting time from dates in JavaScript – here’s how to compare two JavaScript date objects. This article will explore comparing dates/times with different granularity levels – from dates that are an exact month to dates that fall in the same year. Using Boolean Operators Native Javascript date objects can be compared using standard boolean/comparison operators – allowing you to compare dates by checking whether they are equal, not equal, greater than, less than, equal to or greater than, or equal to or … Read more