Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint

Data Types

As I mentioned earlier, JavaScript is a language that is dynamically typed. By this I mean that the language infers a lot of what you can do with certain data by the type of data you use. If you passed 2 + 2 to a JavaScript engine, most likely you want to perform a mathematical operation and get the result of the operation (4) and not print out “2 + 2.” However, if you had “JavaScript” + “Rocks,” adding these together to get a numeric value doesn't make much sense.

In programming languages, these are called data types, and in JavaScript, the JavaScript engine dynamically interprets this information. That's not to say that you don't need to know about data types and sometimes assign them yourself. Why is this important? Didn't I say that JavaScript is dynamically typed? Shouldn't it just work? One hopes it will, but you can get into some issues pretty quickly if you are not a little careful, so it's a good idea to know what is going on under the covers to help debug your code. For me, the biggest issue I have encountered reading code is when someone accidentally places quotes around a numeric data type, or getting Boolean and numeric types mixed. Here is a quick rundown of some of the basic data types....


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint