Home » Programming » Javascript

JavaScript Print – To the Console, WebPage, or a Printer [Examples]

JavaScript Print to Printer, Console, Page

You’ve searched for ‘JavaScript Print’ – so you’re probably trying to output data to the console, to the webpage or to a printer. Here’s how to do all three. Printing to the Console with console.log() The JavaScript console.log() method prints data to the JavaScript console (visible in your browsers web inspector). Any type of data can be logged to the console, including strings, numbers, arrays, and objects, and either the contents of, or a text representation of, the value will be displayed. console.log() is frequently used for debugging – developers use it to view … Read more

Home » Programming » Javascript

JavaScript Escape Quotes / Escape Strings [Examples]

JavaScript Escape Quotes

This article will explain how to use escape characters to escape quotes in strings in the JavaScript programming language, with some examples. What is a String Variable in JavaScript? A string is a type of variable. It represents a series of zero or more characters. Other variable types are numeric, boolean, and array variables. A variable’s type defines what values it can hold and what can be done with it. For example, string variables can be split and joined to form new strings, and numeric variables can have mathematical operations … Read more

Home » Programming » Javascript

How to Use the JavaScript ‘do while’ Loop, With Examples

JavaScript do while loops

This article will show you how a JavaScript do while loop is constructed, and what it us used for, with code examples. do while loops are one of the simplest kinds of loops, and appear in most programming languages. A do while loop runs a block of code repeatedly, until a condition is met. When the do while condition is met, the loop stops. It’s important to get familiar with using loops – and understanding how loops work – as they form the backbone of just about every game and application you might … Read more

Home » Programming » Javascript

How to Convert Array to String in JavaScript with toString() and join()

JavaScript Array to String

This brief tutorial will show you two ways to convert JavaScript arrays to strings using the toString() and join() methods. What Are Arrays? An array is a data structure which holds multiple values. It’s like a numbered list – each item in the array has a value and a position (called the index). The indexes start counting at position 0, so the first item in an array is at index 0, the second at index 1 and so on. Converting Arrays to Strings in JavaScript There are many reasons you may wish … Read more

Home » Programming » Javascript

Array.shift() to Remove First Item from JavaScript Array [Examples]

JavaScript Array Shift

This short tutorial will show you how to use the JavaScript Array.shift() method to remove items from an array, and provide some code examples. JavaScript Arrays An array is a variable type which can hold zero or more values within it. Each value in an array has a position, called the index – which is an integer value representing the items position in it’s order of appearance. Indexes start counting at position 0 – so the first item in an array is at index 0, the second item at index 1, and so on. JavaScript … Read more

Home » Programming » Javascript

NVM Node Version Manager – Why it’s Great, How to Use it in Linux

NVM Node Version Manager Linux

The Node Version Manager (NVM) is an indispensible tool for JavaScript Developers. Here’s why it’s so useful, and how to use it in Linux. What is Node.js Node.js is a JavaScript runtime which allows you to build and run JavaScript apps outside of the web browser. It’s commonly used to build APIs, webapps and even desktop applications. New versions of Node.js are released periodically, with major version releases often breaking compatibility with code written for earlier versions. Managing Code Dependencies Sucks A code dependency is any software … Read more

Home » Programming » Javascript

How to Reverse a String in JavaScript in One Line of Code [Example]

Javascript Reverse String

This quick tutorial will show you how to reverse a string in JavaScript. Strings are Array-Like Strings in JavaScript are considered array-like. A string is an ordered series of characters, so it can be considered as an array of characters. This makes it easy to convert a string to an array. We can then use any one of the methods available for reversing the array to reverse the string. This means you can use any of the methods we’ve previously outlined on reversing arrays on strings. … Read more

Home » Programming » Javascript

How to Sort Arrays in JavaScript with the sort() Method [Examples]

Javascript Sort Array

This tutorial will show you how to sort arrays in the JavaScript programming language with the array sort() method and provide some code examples. What is an Array in JavaScript? An array is a type of JavaScript variable that can hold a series of variables, references to variables, or values. It’s like a list of items. Each item or element in the array has a value and a position. The position is the order the element appears in the array and is called the index. Indexes are zero-indexed – meaning … Read more

Home » Programming » Javascript

How to Generate a Range (Numbers/Letters) in JavaScript

JavaScript Generate Range

This article will show you how to generate a range of numbers or letters in JavaScript, and provide some functions you can copy and paste into your own project. The Python, PHP, and many other popular programming languages provide a range() function, for generating a range of numbers or letters between two values. JavaScript does not have a built-in function for doing this, but it’s easy functionality to implement yourself. Here’s how to do it, and some pre-made functions you can just paste into your own project to use … Read more

Home » Programming » Javascript

Copy/Clone an Array or Object in JavaScript The Right Way [Examples]

How to Copy/Clone JavaScript Array

This tutorial will show you how to properly copy/clone an array or object in JavaScript – it’s not as simple as it seems! Copying an array or object may seem simple – but JavaScript throws a spanner in the works – the fact that when you assign the value of one variable to another it references the original variable. This means that if the value of the original variable is changed, the value of the copy will change too! To get around this, you will need to clone the array – ensuring … Read more