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

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

Performing Actions Until a Condition is no Longer True Using Javascript While Loops

The Javascript while loop is a programming construct that executes a set of statements as long as a certain condition is true. While loops are part of a programming statement class called “control statements,” since they influence the logical flow of a program.

The Javascript standard specifies two different types of while loops: the simple while loop and the do-while loop. Although they have similar functions, important differences between them make them useful in slightly different circumstances.

In this article, we define what a Javascript while loop is and how it differs from the do-while loop. This article also covers some caveats when using either of those loops.

Continue Reading

SQL Top Limit Fetch RowNum — Too Much Of A Good Thing

Relational databases store information in tables — tables with columns analogous to elements in a data structure and rows which are an instance of that data structure. We sometimes need to limit the number of returned rows. SQL Top, SQL Limit, SQL Fetch, and SQL RowNum (the exact syntax varies by database) are our tools in extracting the exact data we want.

In contrast to the usual behavior of the SQL Select statement, returning all relevant data, the limit function in SQL — expressed as one of Top, Limit, Fetch, or Rownum — provides a mechanism for limiting the data returned to either an absolute number or percentage of the rows. Limiting returned rows to bite-sized manageable chunks drastically reduces the storage and processing overhead requirements on software that consumes database data, resulting in a faster and more reliable code.

Rows are stored in databases at random. One adds certainty to which rows are retrieved by crafting the SQL Select statement with a winnowing WHERE clause and an ORDER BY clause. The techniques in this blog entry show how to retrieve a subset of those nicely-ordered rows, or how to iterate through those subsets across the entire results set.

Continue Reading