Lesson 2: Writing, testing, and debugging JavaScript CHAPTER 3 89
C. NaN
D. infinity
- Which of the following represent valid variable declarations? (Choose all that apply.)
A. var switch;
B. var myChar;
C. var $cost;
D. var _total;
E. var 1to1;
F. var tooGood4u; - In your application, you want to display a personalized message to the user, if the
user’s name is populated, in the userName variable, but if userName is empty, you
want to use Valued User instead. How can you accomplish this most efficiently?
A. var personalized = ‘Hello ‘ + (userName ?? ‘Valued User’);
B. var personalized = ‘Hello ‘ + (userName || ‘Valued User’);
C. var personalized = ‘Hello ‘ + (userName && ‘Valued User’);
D. var personalized = ‘Hello ‘ + (userName + ‘Valued User’);
Lesson 2: Writing, testing, and debugging JavaScript
The previous lesson presented an in-depth introduction to JavaScript, and you’re probably
ready to start writing some code, which is what this lesson explains. It starts with writing
code, using test-driven development practices. Along the way, a new project is created, and
a JavaScript file is added, using the <script> element. Finally, this lesson covers the JavaScript
debugging features in Visual Studio.
When working with a programming language, you’ll probably want to create a Hello
World program so you can see what is required to get a simple program to run. Although a
Hello World program was created previously, it was created by using HTML. This time, you
create a JavaScript version of the Hello World program.
After this lesson, you will be able to:
■■Describe test-driven development (TDD).
■■Set up a web application for TDD.
■■Set up a Windows 8 application for TDD.
■■Debug JavaScript code.
Estimated lesson time: 45 minutes