Javascript – How To Code

How To Code in JavaScript

by Lisa Tagliaferri and Tania Rascia

JavaScript is a high-level, object-based, dynamic scripting language popular as a tool for making webpages interactive.

How To Use the JavaScript Developer Console

June 27, 2017

This tutorial will go over how to work with the Console in JavaScript within the context of a browser, and provide an overview of other built-in development tools you may use as part of your web development process.

How To Add JavaScript to HTML

February 4, 2021

This tutorial will go over how to incorporate JavaScript into your web files, both inline into an HTML document and as a separate file.

How To Write Your First JavaScript Program

August 1, 2017

This tutorial will walk you through creating a “Hello, World!” program in JavaScript. To make the program more interesting, we’ll modify the traditional “Hello, World!” program so that it asks the user for their name. We’ll then use the name in a greeting. When you’re done with this tutorial, you’ll have an interactive “Hello, World!” program.

Understanding Syntax and Code Structure in JavaScript

July 5, 2017

In this tutorial, we’ll go over many of the rules and conventions of JavaScript syntax and code structure.

How To Write Comments in JavaScript

June 20, 2017

JavaScript comments are annotations in the source code of a program that are ignored by the interpreter, and therefore have no effect on the actual output of the code. Comments can be immensely helpful in explaining the intent of what your code is or should be doing.

Understanding Data Types in JavaScript

May 31, 2017

In this tutorial, we will go over how data types work in JavaScript as well as the important data types native to the language.

How To Work with Strings in JavaScript

July 11, 2017

A string is a sequence of one or more characters that may consist of letters, numbers, or symbols. Strings in JavaScript are primitive data types and immutable, which means they are unchanging. As strings are the way we display and work with text, and text is our main…

How To Index, Split, and Manipulate Strings in JavaScript

July 14, 2017

In this tutorial, we will learn the difference between string primitives and the String object, how strings are indexed, how to access characters in a string, and common properties and methods used on strings.

How To Convert Data Types in JavaScript

August 4, 2017

This tutorial will guide you through converting JavaScript’s primitive data types, including numbers, strings, and Booleans.

Understanding Variables, Scope, and Hoisting in JavaScript

February 20, 2018

This tutorial covers what variables are, how to declare and name them, and also take a closer look at the difference between var, let, and const. It also goes over the effects of hoisting and the significance of global and local scope to a variable’s behavior.

How To Do Math in JavaScript with Operators

July 20, 2017

In this JavaScript tutorial, we will go over arithmetic operators, assignment operators, and the order of operations used with number data types.

Understanding Comparison and Logical Operators in JavaScript

February 5, 2021

The field of computer science has many foundations in mathematical logic. If you have a familiarity with logic, you know that it involves truth tables, Boolean algebra, and comparisons to determine equality or difference. The JavaScript programming language uses operators…

Understanding Arrays in JavaScript

July 28, 2017

In this tutorial, we will learn how to create arrays; how they are indexed; how to add, modify, remove, or access items in an array; and how to loop through arrays.

How To Use Array Methods in JavaScript: Mutator Methods

August 10, 2017

JavaScript has many useful built-in methods to work with arrays. Methods that modify the original array are known as mutator methods, and methods that return a new value or representation are known as accessor methods. In this tutorial, we will focus on mutator methods.

How To Use Array Methods in JavaScript: Accessor Methods

August 14, 2017

This tutorial will go over methods that will concatenate arrays, convert arrays to strings, copy portions of an array to a new array, and find the indices of arrays.

How To Use Array Methods in JavaScript: Iteration Methods

August 15, 2017

In JavaScript, the array data type consists of a list of elements. There are many useful built-in methods available for JavaScript developers to work with arrays. In this tutorial, we will use iteration methods to loop through arrays, perform functions on each item in an array, filter the desired results of an array, reduce array items down to a single value, and search through arrays to find values or indices.

Understanding Objects in JavaScript

August 24, 2017

Objects are an integral and foundational aspect of most JavaScript programs. For example, a user account object may contain such data as usernames, passwords, and e-mail addresses. Another common use case is a web shopping platform’s shopping cart that could consist of an array of many objects containing all the pertinent information for each item, such as name, price, and weight for shipping information. A to-do list is another common application that might consist of objects.

Understanding Date and Time in JavaScript

October 19, 2017

JavaScript comes with the built in Date object and related methods. This tutorial will go over how to format and use date and time in JavaScript.

Understanding Events in JavaScript

June 19, 2018

Events are actions that take place in the browser that can be initiated by either the user or the browser itself. In this JavaScript aticle, we will go over event handlers, event listeners, and event objects. We’ll also go over three different ways to write code to handle events, and a few of the most common events. By learning about events, you’ll be able to make a more interactive web experience for end users.

How To Work with JSON in JavaScript

December 8, 2016

This tutorial provides an introduction to working with JSON in JavaScript. Some general use cases of JSON include: storing data, generating data from user input, transferring data from server to client and vice versa, configuring and verifying data.

How To Write Conditional Statements in JavaScript

August 29, 2017

In programming, there will be many occasions in which you will want different blocks of code to run depending on user input or other factors. As an example, you might want a form to submit if each field is filled out properly, but you might want to prevent that form from…

How To Use the Switch Statement in JavaScript

September 11, 2017

Conditional statements are among the most useful and common features of all programming languages. “How To Write Conditional Statements in JavaScript” describes how to use the…

Using While Loops and Do…While Loops in JavaScript

September 27, 2017

Automation is the technique of making a system operate automatically; in programming, we use loops to automate repetitious tasks. Loops are one of the most useful features of programming languages, and in this this article we will learn about the while and do…while…

For Loops, For…Of Loops and For…In Loops in JavaScript

September 28, 2017

Loops are used in programming to automate repetitive tasks. In this tutorial, we will learn about the for statement, including the for…of and for…in statements, which are essential elements of the JavaScript programming language.

How To Define Functions in JavaScript

October 7, 2017

A function is a block of code that performs an action or returns a value. Functions are custom code defined by programmers that are reusable, and can therefore make your programs more modular and efficient. In this tutorial, we will learn several ways to define a…

Understanding Prototypes and Inheritance in JavaScript

January 12, 2018

JavaScript is a prototype-based language, meaning object properties and methods can be shared through generalized objects that have the ability to be cloned and extended. This is known as prototypical inheritance and differs from class inheritance. Among popular…

Understanding Classes in JavaScript

May 4, 2018

Understanding prototypical inheritance is paramount to being an effective JavaScript developer. Being familiar with classes is extremely helpful, as popular JavaScript libraries such as React make frequent use of the class syntax.

How To Use Object Methods in JavaScript

August 3, 2018

Objects in JavaScript are collections of key/value pairs. The values can consist of properties and methods, and may contain all other JavaScript data types, such as strings,…

Understanding This, Bind, Call, and Apply in JavaScript

September 13, 2019

The this keyword is a very important concept in JavaScript, and also a particularly confusing one to both new developers and those who have experience in other programming languages. In JavaScript, this is a reference to an object. In this article, you’ll learn what this refers to based on context, and you’ll learn how you can use the bind, call, and apply methods to explicitly determine the value of this.

Understanding Map and Set Objects in JavaScript

February 7, 2020

Introduced in ECMAScript 2015, Maps in JavaScript are ordered collections of key/value pairs, and Sets are collections of unique values. In this article, you will go over the Map and Set objects, what makes them similar or different to Objects and Arrays, the properties and methods available to them, and examples of some practical uses.

Understanding Generators in JavaScript

February 21, 2020

In ECMAScript 2015, generators were introduced to the JavaScript language. A generator is a process that can be paused and resumed and can yield multiple values. They can maintain state, providing an efficient way to make iterators, and are capable of dealing with infinite data streams. In this article, we’ll cover how to create generator functions, how to iterate over Generator objects, the difference between yield and return inside a generator, and other aspects of working with generators.

Understanding Default Parameters in JavaScript

March 31, 2020

In ECMAScript 2015, default function parameters were introduced to the JavaScript programming language. These allow developers to initialize a function with default values if the arguments are not supplied to the function call. Initializing function parameters in this way will make your functions easier to read and help you avoid errors caused by undefined arguments and the destructuring of objects that don’t exist. In this article, you will learn how to use default parameters.

Understanding Destructuring, Rest Parameters, and Spread Syntax in JavaScript

May 11, 2020

Introduced in ECMAScript 2015 (ES6), destructuring, rest parameters, and spread syntax provide more direct ways of accessing the members of an array or an object, and can make working with data structures quicker and more succinct. In this article, you will learn how to destructure objects and arrays in JavaScript, how to use the spread operator to unpack objects and arrays, and how to use rest parameters in function calls.

Understanding Template Literals in JavaScript

June 26, 2020

The 2015 edition of the ECMAScript specification (ES6) added template literals to the JavaScript language. Template literals are a new form of making strings in JavaScript that add a lot of powerful new capabilities, such as creating multi-line strings, using placeholders to embed expressions in a string, and parsing dynamic string expressions with tagged template literals. In this article, you will go over the differences between single/double-quoted strings and template literals.

Understanding Arrow Functions in JavaScript

July 31, 2020

Arrow functions are a new way to write anonymous function expressions in JavaScript, and are similar to lambda functions in some other programming languages like Python. They differ from traditional functions in the way their scope is determined and how their syntax is expressed, and are particularly useful when passing a function as a parameter to a higher-order function, like an array iterator method. In this article, you will find examples of arrow function behavior and syntax.

Understanding the Event Loop, Callbacks, Promises, and Async/Await in JavaScript

September 9, 2020

In order to avoid blocking code in JavaScript development, asynchronous coding techniques must be used for operations that take a long time, such as network requests made from Web APIs like Fetch. This article will cover asynchronous programming fundamentals, teaching you about the event loop, the original way of dealing with asynchronous behavior through callbacks, the updated ECMAScript 2015 (ES6) addition of promises, and the modern practice of using async/await.

Understanding Modules and Import and Export Statements in JavaScript

October 21, 2020

As the importance of JavaScript in web development grows, there is a bigger need to use third-party code for common tasks, to break up code into modular files, and to avoid polluting the global namespace. To account for this, ECMAScript 2015 (ES6) introduced modules to the JavaScript language, which allowed for the use of import and export statements. In this tutorial, you will learn what a JavaScript module is and how to use import and export to organize your code.