Home » Programming » Javascript

How to Include a JavaScript File in Another JavaScript File [Examples]

How to Include a JavaScript File in Another

This article will detail the various methods for including a JavaScript file in another JavaScript file – providing several methods for use in the browser, and when working in Node.js. One of the cornerstones of programming is reusable code. This concept is encapsulated in the DRY (Don’t Repeat Yourself) principle – that if you need to do something multiple times, you write the code for it once, and re-use it where it is required, rather than having multiple copies of the same code in your code base. … Read more

Home » Programming » Javascript

JavaScript Reference: Complete List of Operators + Examples

JavaScript Operators

This article will explain and list JavaScript operators and expressions. JavaScript operators perform a given operation on the provided expressions or values. Common operations include comparisons, arithmetic, and ternary operations. You will use JavaScript operators frequently (even the simplest JavaScript code will use multiple operators!), so it’s worth getting to know them, and their expected behaviour. What are Operators and Operands? Javascript operators perform a given operation, for example addition, subtraction, and other arithmetic, comparisons like greater than/less than, and more complicated operations like ternary/comparison … Read more

Home » Programming » Javascript

Checking for Equality (And Inequality) in JavaScript, with Examples

Equality and Inequality JavaScript

This article will explain equality and inequality in the JavaScript Programming language, and provide code examples showing how to check if values are equal in value and type. Checking whether two values are equal can get a bit confusing in JavaScript – there is loose equality and strict equality involving types to consider. Read on to find out how testing for equality and inequality works in JavaScript. What are equality and inequality? In programming, equality is the process of checking whether two values are equal … Read more

Home » Programming » Javascript

JavaScript for Loops – How to Use Them [Examples]

How to use for loops in JavaScript

This article will show you how to use the simplest JavaScript loop – the for loop, and provide code examples. JavaScript for Loops JavaScript’s for loops are used to execute a block of code repeatedly until a condition is met. The initial variables, condition that must be met, and the expression which progresses the loop are all defined within the loop expression. for loop Syntax JavaScript for loops follow the following syntax: for (INITIALIZATION; CONDITION; FINAL_EXPRESSION) { //Code to be executed in the loop } Note that: INITIALIZATION sets the variable which is used to control … Read more

Home » Programming » Javascript

How to Use Nested For Loops in JavaScript, with Examples

JavaScript nested for loops

This article will quickly explain nested for loops in JavaScript, how they are used with multidimensional arrays, and show some examples. For Loops We’ve already covered for loops – check out our article here. To sum up the article, for loops repeat a block of code for a given number of iterations: for (let i = 0; i <= 3; i++) { console.log(i); // Will output the numbers 0-3 to the console } Above, a for loop is defined that defines an initial variable i that is used to control the loop, sets a … Read more

Home » Programming » Javascript

Filter JavaScript Array With Multiple Conditions/Values [Examples]

JavaScript filter array using multiple conditions/values

This article will show you how to filter an array using multiple conditions, to return multiple values. Example code is provided. We’ve already covered filtering arrays in general – this article covers specifically how multiple conditions can be used with the Array.filter() method. The Array.filter() Method The filter() method is available on all arrays in JavaScript. It creates a new array, containing only the items from the original array which passes all conditions in a provided function. filter() Method Syntax The syntax for the array filter() method is as follows: ARRAY.filter(ELEMENT => FUNCTION) Note that: ARRAY is … Read more

Home » Programming » Javascript

The JavaScript valueOf() Method – What Does it Actually Do?

JavaScript valueOf()

This quick tutorial will explain the JavaScript valueOf() Method, what it does, and why you might use it. The JavaScript valueOf() method gets the primitive value of the object it is called from. Usually you will not need to call it, however it does have its use cases. Primitives vs Objects In JavaScript, a value or variable has a type of value. A primitive is a value that is not an object, with no methods or properties, representing only the data that it exists as. JavaScript has 7 primitive data types: string number bigint boolean undefined … Read more

Home » Programming » Javascript

Check/Validate String Matches Regex in JavaScript [Examples]

JavaScript regex match

This article will show you how to use Regular Expressions (Regex) to validate matching strings in JavaScript. All user input collected in your applications should be validated. If an email address is required, a valid email address should be entered, or sending the email will fail. If a phone number is required, a valid phone number must be entered, and so on. Regex can be used for this validation by matching a whole string to a specified format. Regex can also be used to search … Read more

Home » Programming » Javascript

for…in Loops in JavaScript – How to Use Them

JavaScript for...in loop

The for…in loop in JavaScript loops over all of the properties in an object. This article will explain why and how to use it. JavaScript Objects JavaScript objects are a kind of variable which store the properties for an item you are representing in your code. For example, you may have a car object, which of which the make, year, model, and colour of a car are it’s properties. Each car object would have it’s own separate list of properties which define that car. JavaScript objects can also be used as hash tables – providing … Read more

Home » Programming » Javascript

Remove Page Elements using JavaScript RemoveChild [Examples]

JavaScript removeChild()

The Node.removeChild() method removes HTML Element from the current page via the DOM. This article will show you how to use it. The DOM in JavaScript The HTML DOM (Document Object Model) is the interface which JavaScript uses to interact with HTML page elements, including adding, removing, and modifying on-screen items. It is the data structure which represents every HTML tag present on a page – everything from the root <html> element that wraps the page to every <div>, <p>, <input>, and <span> – everything on the page is represented in the DOM, both … Read more