3D Game Programming

(C. Jardin) #1

CHAPTER 7


A Closer Look at JavaScript Fundamentals


Before we go further, let’s take a closer look at JavaScript. Like any other
programming language, JavaScript was built so that both computers and
people could understand it.

JavaScript programming can be thought of as describing things and what
those things do, just like English and other languages. When we built our
avatar, we used JavaScript to describe its head, hands, and feet. We also
described how the 3D renderer should draw the scene in our browser. To put
it all together, JavaScript has keywords that both computers and humans
can understand.

Let’s have a look.


8.1 Getting Started


Instead of drawing and moving shapes in this chapter, we’re going explore
the JavaScript programming language. We can do a lot of this in the JavaScript
console, so start by opening that. Refer back to Section 2.2, Opening and
Closing the JavaScript Console, on page 18, if you do not remember how.

Some of the JavaScript that we’ll look at is too big for the JavaScript console.
For that, we need to create a new project in the ICE Code Editor. Use the 3D
starter project template and call it Just JavaScript.

Code in the JavaScript Console.
We’re just introducing things in the beginning of this chapter, so
it’s easiest to play with it in the JavaScript console. Be sure to
experiment!

7.2 Describing a Thing in JavaScript


Have you noticed how we introduce new things in JavaScript?


When you’re done with this chapter, you will


  • Know what many of those JavaScript
    things, like var, are

  • Be able to write code that does things only
    when you want it to


Prepared exclusively for Michael Powell report erratum • discuss

Free download pdf