Comparing Values by Using Operators: Javascript AND, Javascript OR, and Many More

Comparing one value to another is an important programming technique that developers use to create logical flows. Javascript provides many ways to compare simple values using language constructs called “operators.”

The Javascript standard defines two different types of simple operators.

  • Logical Operators — logical relationships between values
  • Comparison Operators — how values are related to each other

These operators work with Javascript data types that hold simple values, like strings or numbers, but cannot handle complex values like Javascript objects, arrays, or functions. To compare complex objects, developers must write their own comparison functions.

Make sure that the compared values or variables are the same data type; otherwise you may get an answer you don’t expect. Each operator type has different rules for valid comparisons, which the next sections will cover in more detail.

Continue Reading

Handling Errors with Javascript Try Catch Statements

To the surprise of many programmers, errors in Javascript programs are not always a mark of bad programming. Sometimes, it’s important for an error to occur so a programmer knows something is wrong, like when a program doesn’t get the input it needs or can’t connect to a resource properly.

By default, a Javascript error prevents the execution of any more Javascript code. In some contexts, though, developers might want to skip over an error and continue executing a program. This process is called error handling, and Javascript manages this with special code structures called Javascript try catch statements, defined in the Javascript standard.

Continue Reading

Creating and Managing Program Output: Javascript Print Strategies

Developers use Javascript to create web content, format web pages, and return values from supporting functions that do calculations. Developers often need a way to track what Javascript code is doing, so they generate Javascript output.

The Javascript standard documents two major techniques for generating output: printing to the developer console and printing into HTML on a web page.

Continue Reading

How to Manage Multiple Values with Javascript Arrays

A Javascript array is a type of variable that holds multiple valid Javascript values. There is no limit to array size except for the amount of memory available when creating the array, according to the Javascript standard.

Since Javascript arrays can hold multiple values, programmers can group related information together, from sports scores to grades. Indexing values in an array makes it easy to access related values quickly and to perform calculations without having lots of extra variables.

Javascript arrays help developers keep variables and values organized in an easily accessible way inside a program. In this guide, we’ll walk through how to manage multiple variables and values with Javascript arrays.

Continue Reading