Appendix C. Programming Concepts

Many graphic designers want to use the scripting capability of SVG as described in Chapter 13. If they’re not familiar with programming, they tend to practice what might be called voodoo scripting. In the popular-culture stereotype,[36] voodoo works by reciting a mysterious spell and hoping that your enemies die horribly. Voodoo scripting works by copying someone else’s mysterious script into your SVG document and hoping that your document continues to live. We’re under no illusion (nor even a spell) that reading this brief, purposely oversimplified summary will turn you into a master programmer. Our goal is simply to introduce enough of the elementary programming concepts to remove some of the mystery from the scripts that you copy and modify. The particular programming language that we will discuss in this appendix is called ECMAScript; it is the standardized version of the JavaScript language. The concepts used in ECMAScript are common to many other programming languages.

Constants

A constant is a fancy word for a number or string of characters that never changes. Examples are 2, 2.71828, "message", and 'communication'. The last two are called string constants. In ECMAScript, you can use either single or double quotes to mark the boundaries of a string. This is good if you ever need to write things like "O'Reilly Media" or 'There is no "there" there.'

You will sometimes see the two Boolean constants true and false, which are used for yes-or-no situations. ...

Get SVG Essentials, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.