objects. We will talk more about objects in the next class, but for now, objects are broken down further into
arrays, which we will talk about today. Also look out for error literals, like
NaN, which stands for "Not a Number", which is exactly what the value means. You will get that if you try to evaluate a string that cannot be parsed to a number. You can test for
NaN using the
isNaN() function. Try writing this in the console:
length, a property that returns the length of the string. Try this in the console:
Strings also have some built in methods like
replace() which help us do evaluation and manipulation.
"Hello World".charAt(0); "Hello World".replace("World", "Jerry");
Booleans default to the values
false, such as
"" (empty string),
undefined. Everything else defaults to
true, such as
-99. Try evaluating some booleans in the console with this syntax:
Boolean(""); Boolean(null); Boolean(4);
array is an object that contains a list of variables, such as this:
imgs will return
"cat.jpg". Like strings, arrays have a
length property. Try creating an array, reading from the list, and returning the length:
myArray = ["cat", "dog", "alligator"]; myArray.length; myArray; myArray;
Arrays can be populated by creating a new Array or assigning values. Arrays can have any length, and unassigned spots will have the value
myArray = "bird"; myArray; myArray;
Arrays are useful for looping through data structures to perform functions and operations.
undefined as distinct values.
null indicates a purposely unassigned value.
undefined indicates a variable has not been instantiated, or created.