-
Notifications
You must be signed in to change notification settings - Fork 4
Datatypes 2
When we are programming we must know what kind of data we are working with. Is our variable a Number, a String, an Object, something else? The programming word for kind of data is datatype. In Javascript there are 3 categories of datatype: simple, collection, and function.
Data is said to be of a simple type when it can only represent one thing at a time. The simple data types are:
A Number in javascript can be any number between 9,007,199,254,740,992 and -9,007,199,254,740,992. That's a lot of numbers! Numbers can also include a decimal part. To write a number we just type it out though we cannot use commas!
// some valid numbers
0;
12;
193874;
-100;
234.2304980;
-2345823059830193.13981798;
// some invalid numbers
//┌ Can't use commas!
10,000;
// ┌ Too many decimal points!
134.1309.7;A String in Javascript can be any string of characters. It is called a string because javascript doesn't see words or meaning, it only sees a bunch of individual characters coming one after the other. There is no maximum length of a string though it is limited by the size of your computer's memory. To write a string we first start with a quote character, then we can have any character except that same quote character then we must end with the same quote character. There are 2 quote characters that Javascript lets you use: single quote -> ' and double quote -> ". All characters inside a string are significant this is including spaces, punctuation, and symbols. Remember: All characters in a string are significant.
// Some valid strings
// ┌ Double Quote ┌ Double Quote
"If you can't stand the heat,";
// ┌ Single Quote ┌ Single Quote
'stay out of Miami.';
// ┌ The smallest string: empty string!!
"";
// ┌ This string is 5 space characters
" ";
// ┌ Single Quote ┌ Single Quote
// ⇣ ┌ We can⇣put one quote type inside another
'We built a "lazer".'
// Some invalid strings
// ┌ Double Quote ┌ No closing quote!!
"I thought I told you;
// ┌ Double Quote ┌ Non matching closing quote!!
"That we wont stop'
// ┌ Double Quote ┌ Oops!!
"To take the wold hostage we've built a "Lazer"";TODO: Escape Sequences
A Boolean in programming is a piece of data that can either be true or false and nothing else. There are no other possible values for a Boolean! This is extremely useful as many programming instructions function simply by checking whether a comparison is either true or false. Such simplicity!
// Some valid Booleans
true;
false;
// Thats it!!! Nothing else is a valid Boolean.
// Some invalid booleans.
// This is a string, not a Boolean!!
"true";
// This is not valid, all letters must be lowercase!!
True;In Javascript undefined means no value. When we declare a variable but don't assign it it is undefined. When we write a function that has no return value the function returns undefined.
// ┌ We declare a variable but don't assign it.
var someVariable;
someVariable === undefined; // This is true
// ┌ This function doesn't return anything.
function yay(){ 2 + 2; }
yay() === undefined; // This is also true
// ┌ We declare a person variable and assign it an empty object.
var person = {};
person.name === undefined; // Also true- NaN
- Regular Expressions
- Null
Coming Soon!
Coming Soon!