Javascript Examples: An Overview of Udacity’s Javascript Code

Javascript is one of Udacity’s most useful language resources when you want to learn about web development. Our Javascript hub contains many examples of Javascript code, but it might seem overwhelming to keep track of it all if you’re just starting out. That’s where this article comes in: a one-stop repository of Javascript examples.

Use this article to get a general idea of how Javascript works and to become familiar with its syntax. It also includes examples of JSON, a data exchange language modeled on some characteristics of Javascript. Every Javascript example contains a link back to a Udacity article that explains more about that Javascript code.

You can test these examples, and any example in Udacity’s Javascript articles, at Play Code,



Continue Reading

Javascript Hub: Strategies to Create Dynamic Web Pages

Javascript is a vital part of dynamic content on the modern web. From simple scripts to complex interactions that require frameworks, Javascript enhances user experiences on the web.

There are two major types of Javascript, and this Udacity Javascript hub covers both. The first type is “vanilla” Javascript, scripts you can write using the basic rules in the Javascript standard. The second type is framework-driven Javascript that creates complex content building upon others’ frameworks, like Angular and React or libraries like FusionCharts.

This Javascript hub contains easy-to-follow guides on a wide range of Javascript topics. Most articles provide sample code to demonstrate how Javascript works in the real world.

This hub is meant to be a comprehensive resource, so we will add new content as it’s published. Check back here for more Javascript content.



Continue Reading

Clarifying Code with Javascript Comments

Javascript is built for simplicity and ease of use, but it’s still possible to create complex code that isn’t easy to understand at a glance. For these situations, the Javascript standard provides two ways to create code comments where developers can explain in plain language what is happening.

Although a browser doesn’t execute Javascript comments, including comments is an important best practice in software development. Nearly all Javascript code can benefit from the addition of comments to explain how it works; adding useful comments is a sign of good code quality.

This article covers how to create Javascript comments, how they’re used within a program, and some best practices for creating the most effective comments possible.



Continue Reading

Deciding on a Page Address with Window.location

Javascript is well-known for its ability to modify content on a web page. Less well-known is its ability to move between web pages programmatically so users don’t have to manipulate the browser manually by clicking on links or browser control buttons.

The Javascript standard provides an object called Window.location to handle changing a web page’s address and many other actions. These actions do not directly affect the Document Object Model (DOM) of a particular web page, and may load a new document.

The “location” part of Window.location is its own object type. The Location object is not unique to the Window object that controls the web browser. A single web page can support multiple Location objects.

Window.location is unique because it doesn’t require knowledge of anything on a web page to work. Location objects contain over a dozen properties and methods, and all of these are available to the unique Window.location object.

This article will cover the most commonly used properties and methods of Window.location.



Continue Reading

Managing Dates with Javascript Date Formats

Javascript date formats are notoriously quirky — they are a critical part of many websites, but they’re difficult to implement correctly in a cross-browser fashion — and have caused developers many headaches. The Javascript standard provides three different formats for Javascript dates, and each format has different uses.

Some variations in Javascript dates happen simply because of the browser you use, especially when adding a specific time. Developers need to be aware that the same code handling a date can work differently on different browsers. This is less of a problem in modern browsers but some irregularities still remain.

This article will go over the various types of Javascript date formats and why Javascript has a preferred format for both dates and times. Then, we will examine the quirks that browsers present when working with these formats.



Continue Reading

Complex Manipulations of Javascript Arrays with Javascript Array Methods

A Javascript array is a special type of variable that holds multiple valid Javascript values. They help developers keep related values and objects together, while also providing the ability to change elements independently without affecting any others.

let example0a = ["a", "c", "c", 1, 2, 3];
example0a[1] = "b";
// Array after this change: ["a", "b", "c", 1, 2, 3];

Javascript arrays are distinct from JSON arrays because the contents of Javascript arrays are changeable. Many methods exist to change their contents or make them easier to handle. The Javascript standard defines 10 different methods specifically designed for manipulating Javascript arrays.

Some Javascript array methods change the contents of the array they act upon, while others do not. Some methods return a new array, while others perform an operation and return the length of the resulting array, and yet others return other, operation-appropriate, values.

This article describes each of the Javascript array methods, what they do, and what values they return. The list of methods is presented in order of increasing complexity, starting with those that don’t change an array’s contents.



Continue Reading

Storing User Data with Javascript Cookies

Here’s an interesting revelation about Javascript: Since Javascript is a client-side web development language, it has access to information about a user that other programming languages don’t.

The Javascript standard provides developers the chance to enhance user experiences using that data via Javascript cookies. 

Every web user has heard of a cookie at some point; we have to accept them at most websites we visit. Usually, we choose to accept them because a dialog box blocks our way, and then we go about our day. Those dialog boxes don’t tell us much about what a cookie is, though, and how many of us have really stopped to think about what they are?

In this article, we describe what Javascript cookies are and how they make your web browsing experience more interesting. Then, we’ll go over how developers manipulate and manage Javascript cookies.



Continue Reading