Taylor Hasenpflug

Software Developer

JavaScript: Basics of Data

Data in JS (JavaScript) is stored in packets called variables. JS isn’t strongly typed like other languages, so the keyword var is used for any variable.

To create a variable, start with the keyword var followed by an acceptable symbolic name for the variable ( data in the following examples ).

To assign a value, the variable name must be to the left of an equals sign, with the new value on the right side.

var data
data = 123
// or
var data = 123

Sometimes you’ll see the keywords let or const instead of var. They have slightly different uses, but var will work 99.99999% of the time.

If a var isn’t given any value, it’s considered undefined or null. Null is a keyword used to indicate an empty value. You can use null to erase a variable too.

var data
// or
var data = null
// or 
var data = 123
data = null

Numbers

Numbers are any valid number values- whole numbers, decimals, etc. There is no distinction between ints and floats, etc.

var data = 1
// or
var data = 1.174
// or
var data = 0x8A4F

For more information about built-in number methods in JavaScript, go here: https://www.w3schools.com/js/js_number_methods.asp

Strings

Strings are groups of one or more characters, surrounded by single or double quotes, or backticks. Strings can be made up of numbers, letters, symbols, etc.

var data = 'string'
// or
var data = "string"
// or
var data = `string`

For more information about built-in string methods in JavaScript, go here: https://www.w3schools.com/js/js_string_methods.asp

Booleans

A boolean is a simple true or false value. This can be set to a variable literally using the true and false keywords, but other values work too. Non-zero numbers, for instance, evaluate to true, while 0 and null evaluate to false.

var data = false
// or
var data = 0
// or
var data = null

For more information about how JavaScript handles boolean values, go here: https://www.w3schools.com/js/js_booleans.asp

Data can also be stored in more complex data storage structures, like arrays and objects. Arrays are a group of variables addressable by a single name. Objects can have properties, methods, etc, similar to other languages. Those will be covered in part two.