Chapter 2 - Data And Decisions Flashcards
What is a number?
A number, including floating points number
What is a string?
A series of characters
What is a boolean data?
True or false
What are the 3 primitives data types?
String
Number
Boolean
What is Null?
Even though a variable had been created, its current value is Null or nothing
What is Undefined?
Indicates that something has not been defined and given a value
How does string data must be encloses?
Between ‘ ‘ or “ “
How to write a string like Paul’s character?
Document.write(“Paul’s character”)
Use the “ because there is a ‘ in the string
What are escape séquences?
To use character that can’t be typed using a keyboard
\b
Backspace
\f
Form Feed
\n
Newline
\r
Carriage return
\t
Tab
'
Single quote
"
Double quote
\
Backslash
\xNN
nN is a number from hexadecimal
\uDDDD
DDDD is hexadecimal from Unicode
+
Adds
-
Substracts
*
Multiply
/
Divides
%
Modulus
–
Decrease By 1
++
Increase By 1
+ with non number
Concatenate
How to name variable?
Camel notation anusToMouth
Prompt()
Ask the user a value and returns it to the code
Var eurosToConvert = prompt(“How many…”, “”);
Typeof()
Know the type of data
Number()
Tries to convert to number
Parsefloat()
Tries to convert to a floating number. Or NaN
ParseInt()
To an integer
3 objects from javascript
String
Date
Math
How to create a string object?
Implicit and explicit
Object.length
Give the length of a string object
Explicit string?
Var MyStringObject = new String( “abc” );
UserEmail.indexOf( “@” ); ?
Return -1 if No @ found
myOldString.substring( 2, 5);
Return character 3 to 5 because it starts at 0 and doesn’t include the last one (5)
How can I create Date objects?
Only explicitely Var todaysdate = new Date();
How to specify the month of a date?
3 First letter
Date object parameter
Var someDate = new Date( aYear, aMonth, aDate, anHour, aMinute, aSecond, aMillisecond)
Where does date month start count ing?
0
Date objects method?
getXXXX and setXXXX
What does setDate(32); so?
Go to the next month (useful to add days)
How to create a math object?
Only implicitely
Does the math object store data?
No
How to call a math object method?
Math.methodOfMathObject( aNumber )
Math.parseInt()
Remove the decimals
Math.round()
Round as usual
Math.ceil()
Always round up
Math.floor()
Rounds down
Math.random()
Random between 0 and 1
Use of an Array?
Store data
How to initialize an Array?
Var preInitArray = new Array(“First Item”, “Second Item”, “Third Item”);
How to Set an Array to hold 3 items?
Var PreDeterminedSizeArray = new Array( 3 );
How to create an Empty Array?
Var anArray = new Array();
How to add new items to an Array?
anArray[0] = "anItem"; anArray[1] = "anotherItem";
Shortcut notation to add to an Array?
Var myArray = [ 1, 2, 3];