Home » Programming » Javascript

Concatenating (Joining) Strings in JavaScript [3 Methods]

javascript string concatenation

Being able to concatenate (join) two or more strings together is pretty useful – you may be combining user input for storage in a single database column or doing the reverse – combining data from multiple database columns into a single string for display or output. There are several ways to concatenate strings in Javascript, and we’ll cover these methods below, along with some useful examples. The string.concat() Method The string.concat() method will join any number of strings to a given initial string. Syntax string.concat(string1, string2, string3…) Note that: string is … Read more

Home » Programming » Javascript

Javascript String includes() Method – Check if a String Contains Another String

Javascript String includes

Here’s a guide on checking whether a string contains another string in the JavaScript programming language using the includes() method. includes() Syntax string.includes(search, start) Note that: string should be a string value or variable search should be the string you are checking for start is the index (position) you want to start searching at. It’s optional Indexes start counting at 0 – The first character of the string is at index 0 returns bool Examples var string = “Linux all over the world”; var result = string.includes(“over”); // Will … Read more

Home » Programming » Javascript

Using JavaScript try/catch/finally Statements [With Examples]

JavaScript try catch finally

This tutorial explains how to use the try/catch/finally statements in Javascript to handle errors, with some useful examples. Sometimes an error is expected – and rather than wanting the application to halt execution on the error; you want to do something else. Other times, an error is unexpected or detrimental to the running of an application, and you want to make sure that it is reported. try/catch statements in JavaScript let you do this. try/catch will attempt to run a block of code and take a specified action … Read more

Home » Programming » Javascript

Array slice() Method in JavaScript, with Examples

Array slice in JavaScript

We have covered removing items from arrays in JavaScript, as well as checking whether an item is present in an array. This article will look at copying or returning a subsection of arrays using the slice() method in Javascript. slice() Syntax arr.slice([start[, end]]) Where: arr is an array or existing array variable start is the index to start the slice at If it is undefined, it will default to 0 The index is the position of the item within the array. Remember, they start at 0! end is the index to end the slice at If it … Read more

Home » Programming » Javascript

Using JavaScript ‘toLowerCase()’ String Method [with Examples]

JavaScript toLowerCase

Want to make a string all lower case in JavaScript? It’s the toLowerCase() method to the rescue! The toLowerCase() method is part of the string object and has full support in all browsers. In JavaScript, strings can either be a primitive or an object – primitives are the most basic kinds of variables, which are not objects, have no methods, and simply represent the given characters. However, String objects have useful methods for manipulating and measuring the string – like toLowerCase(). By default, JavaScript’s string variables are initialized as primitives – but will be automatically … Read more

Home » Programming » Javascript

Measuring the Length of a String in JavaScript, with Examples

Measuring the Length of a String in JavaScript, with Examples

In this guide, we explain how to measure the length of a string in JavaScript using the length method. JavaScript is a flexible programming language that runs just about everywhere. You can run JavaScript apps in web browsers, build command-line apps you can run in the terminal, mobile apps can be built using platforms like Cordova, and server processes can be written on platforms like Node.js. Naturally, Linux is the environment of choice for many JavaScript developers and is perfect for learning tools like Node.js … Read more

Home » Programming » Javascript

Check Array Contains a Value in JavaScript, with Examples

Determining Whether an Array Contains a Value

This tutorial will show you how to check whether an array contains a specific value in Javascript, with full examples. JavaScript is a flexible programming language that runs just about everywhere. You can run JavaScript apps in web browsers, build command-line apps you can run in the terminal, mobile apps can be built using platforms like Cordova, and server processes can be written on platforms like Node.js. Naturally, Linux is the environment of choice for many JavaScript developers and is perfect for learning tools like … Read more

Home » Programming » Javascript

Removing an Element From an Array in JavaScript, with Examples

Removing an Element From an Array in JavaScript

There are multiple ways to remove an element from an array in Javascript. We cover all of the methods that can be used in this tutorial. JavaScript is a flexible programming language that runs just about everywhere. You can run JavaScript apps in web browsers, build command-line apps you can run in the terminal, mobile apps can be built using platforms like Cordova, and server processes can be written on platforms like Node.js. Naturally, Linux is the environment of choice for many JavaScript developers and … Read more

Home » Programming » Javascript

How to Use “if… else” in JavaScript (with Examples)

"if... else" in JavaScript

JavaScript has quickly become one of the most popular programming languages due to its ease of use and flexibility – it can be run in just about any web browser on any device making it perfect for cross-platform apps. Linux is the most popular platform for hosting JavaScript Apps built with Node.js and is a great platform for developing both standalone JavaScript programs and browser-based solutions. If you’re learning JavaScript the if… else control structure is one of the first things you’ll want to get the hang … Read more