Tag Archives: javascript tutorial

The Benefits to Learning JavaScript

Whether you’re seasoned or new to programming, JavaScript is an essential language to have under your belt. Its “write once and run anywhere” mechanics allow users with different programming systems to easily run this language, creating an interface that’s easy for many to use.

Most commonly seen on e-commerce based system or universities who require a programming language that can span different spoken language and be run on any computer system, JavaScript is quickly becoming the necessity to learn for any office or business that seeks to thrive.

But what other benefits exist for you? What can it give you?

1. Networking capabilities

Considered to be network-centric to many, JavaScript makes it easy to work with others across networks and or create platform that easily fit into the perimeters given

2. Performance

JavaScript runs in byte codes, as opposed to native-machine-language commands…this means that Java can work faster to translate its codes rather than working to translate an exclusive language

3. Organized

JavaScript runs its system based on coordinated object-oriented units, known as: classes. These classes are stored away into appropriate files and only called out by the system when they are needed…which improves the speed and efficiency of running time

4. International Use

Unlike other programming languages that run on 8-bit characters that only work with Western spoken languages, Java uses a 16-bit character system that can translate to languages used all across the world.

Don’t hesitate to teach yourself something that could extend the reach of your business, or increase the current efficiency of your product’s running systems. Take the time to learn this language now, and save tons of time, and translation troubles from finding you later.

Thumbnail for 637



JavaScript 1.8 tutorial video: Objects — Working with Windows

Expert Instructor: Don Kiely

Thousands of developers worldwide use LearnNowOnline to gain the technical skills they need to succeed on the job and advance their career.

Object Comparisons in JavaScript


In our last article, we discussed Escape Sequences in String Literals and their use in JavaScript. In this article, we’ll take a deeper dive into JavaScript and look at the use of object comparisons.

Object Comparisons

Unlike primitive values, JavaScript compares objects by reference. This means that two object variables are equal only if the two variables hold a reference to the same object in memory. If the two variables hold a reference to two different objects in memory, even if the objects are the exact same—have the same properties, in the same order, all with the same values—the object variables are not the same.

Some code will show how this works. It starts by creating two objects in memory, obj1 and obj2, each with an identical set of properties each set to the same value. The first comparison checks to see if these objects are equal, which they are not. Then the code creates another object variable, obj3, and sets it to reference obj1. This time, because obj1 and obj3 both hold a reference to the same object in memory, the comparison is true. You can see these results in Figure 21.

Figure 21. Comparing Objects.

Next the code changes a value in obj1, setting its t property to 10. The code then displays the value of t for each of the three object variables and once again tests to see if obj1 is equal to obj3. You can see the results in Figure 22, which shows that t in obj1 and obj3 are still equal, but obj2 is unchanged because it is an entirely different object.

figure 22 changing value of an object with two references
Figure 22. Changing the value of an object with two references.

If you want to make a copy of an object in memory, rather than having two variables that reference the same object in memory, you have to write the code to do it. The following code shows two ways to copy an object. The first is a brute force way to do it, creating an empty object that will be the copy, and writing code to copy the value of each property from obj1 to obj4. The second way uses some nice features of JavaScript objects to loop through the objects’ property collection and the [] notation to reference object properties instead of the dot (.) notation.

WARNING! This is not robust code for copying objects in memory. It copies only one level of properties—you can have object properties in addition to primitive values—and will copy a base object’s properties as well, if any. There are ways to robustly copy objects in JavaScript, but that will have to wait until you learn more about JavaScript objects. Figure 23 shows the results displayed in the Console panel.

figure 23 results of creating two new duplicate objects in memory
Figure 23. The results of creating two new duplicate objects in memory.

If you want to inspect either obj4 or obj5, you can switch to the Scripts panel and put a breakpoint on the last line of code, the final console.log statement, and refresh the page. Then hover the mouse over either obj4 or obj5 to see its properties and values, as shown in Figure 24. As you can see, the properties of obj5 are identical to those in obj1 (remember that the code earlier changed it to 10).

figure 24 inspecting properties of an object in scripts panel
Figure 24. Inspecting the properties of an object in the Scripts panel.

TIP: When you first go to the Scripts panel, it may not have the JavaScript code
from the page loaded. Just refresh the page, and the panel should display the

Get more JavaScript training Today!

Escape Sequences in String Literals Using JavaScript

Thumbnail for 692

One of the fundamental tasks handled by programming languages is to temporarily store and manipulate bits of data in memory, mostly strings and numbers, but often also dates and other special data types, called values. One of the defining characteristics of a programming language is the data types it supports and the features it has for working with those types. A language’s types define the kinds of values you can represent and work with. When you need to save a value for later use in the program, you can define a variable and store the value in it. A variable is a symbolic name for the value that you store in memory, and lets you refer to the value by name and, over the course of program execution, assign different values to the same variable.

Following is an explanation of Escape Sequences in String Literals and their use in JavaScript.

Escape Sequences in String Literals

When you need to include any of a number of characters that have special meaning within a string literal, you can create an escape sequence using a backslash to identify the special character. For example, if you absolutely must include the type of quote used as a string delimiter within the string, you can create an escape sequence as in the following string literal. By making it an escape sequence, the single quote will appear within the string, even though that is also the string delimiter.

The reason why this is called an escape sequence is that the backslash causes an escape from the usual interpretation of the single quote character in the previous example. Table 2 lists the available JavaScript escape sequences.

If you include the backslash in front of any other character than those shown in Table 2, JavaScript will ignore the backslash, such as if you include * in a string literal. This is risky however, because future versions of JavaScript could define new escape sequences that would give meaning to the sequence in your code. As unlikely as that may seem, it’s best to avoid the possibility of broken code in the future.

The following code demonstrates some of these escape sequences. Some lines are broken in random places to fit on the page, but each console.log statement should appear on a single line in a code file. Figure 3 shows the results in the Console panel.


Figure 3. The results in the Console panel of running sample escape sequence code.

Get more JavaScript training Today!