Data Types

JavaScript is loosely typed, which means that, unlike many programming languages, there is a lot of flexibility in terms of how variables are used.

Note that all JavaScript datatypes sometimes act like objects, whether it's a string that can have a method applied to it or a Boolean that can be created using a constructor. That's part of JavaScript's charm.

Strings

Strings are the most generic data type, consisting of zero or more characters that can be concatenated and parsed in a few ways. For example:

greeting = "Hello World"

creates a variable called greeting with a value of "Hello World."

The first time you use a variable, you can optionally declare it. It's also a good practice to put a semicolon at the end of a line:

 var greeting ...

Get Essential ASP for Web Professionals now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.