[toc]
In JavaScript, ==data types can fall into one of two categories primitive or object types.==
==A primitive data type (PDT) is a basic buildinging block.** Using PDTs, we can build more complex data structures or object data types (ODTs).
While ODTs such as objects and arrays are mutable, PDTs are immutable. Remember, ==immutable data types are data types that cannot be cahnged once the value has been created.==
PDTs include:
- Strings
- Numbers
- Booleans
undefinednull
==undefined is a PDT in JavaScript which is assigned to declared varaibles which have not been initialized.==
let x;
console.log(x); // undefined==null is assigned to values that the programmer wishes to keep empty. It is similar to undefined in that it represents an unknown value, but the programmer defines it as such.==
let x = null;
console.log(x); // nullLet's say we are still working for the zoo. WE have objects created for animals like so:
let giraffe = {
species: "Reticulated Giraffe",
name: "Cynthia",
weight: 1500,
age: 15,
diet: "leaves"
};Now, a new giraffe is coming to the zoo. We may want to initalize an object for the giraffe, but hold off on storing how much the giraffe weights until we can weigh it on the scale when it gets here. In this case, we would initialize the weight property like so:
let giraffeTwo = {
species: "Reticulated Giraffe",
name: "Alicia",
weight: null,
age: 10,
diet: "leaves"
};This way our object is properly initilized with all the information we could need and we can update the weight property ler when we have accurate information.
❓ Question: Which of the following are primative data types? Mark all that apply.
a. arrays b. Strings c. objects d.
null❗ Answer: b. and d.
❓ Question: Consider the following code block:
let x; console.log(x);
xis of what type? a.nullb.undefinedc.NaNd. number❗ Answer: b.
undefined
🏁 This one was short! Why can't more chapters be like this? Sadly these were exceptions to that. Speaking of exceptions, let's move on to Chapter 17.
#LaunchCode