comfort_level: 3
completeness: 5
// What is the return value of the below code sample? Provide a sentence or two of explanation.
typeof( 15 );
number
15 is a number.
// What is the return value of the below code sample? Provide a sentence or two of explanation.
typeof( "hello" );
string
the word hello is in quotes, and therefore is a string.
// What is the return value of the below code sample? Provide a sentence or two of explanation.
typeof( [ "dog", "cat", "horse" ] );
string
all three are strings
// What is the return value of the below code sample? Provide a sentence or two of explanation.
typeof( NaN );
undefined
NaN is neither a string, number, or boolean
// What is the return value of the below code sample? Provide a sentence or two of explanation.
"hamburger" + "s";
hamburgers
string + string causes js to recognize as cat
// What is the return value of the below code sample? Provide a sentence or two of explanation.
"hamburgers" - "s";
NaN
two strings are being subtracted, but the subtraction operations causes js to expect two numbers
// What is the return value of the below code sample? Provide a sentence or two of explanation.
"johnny" + 5;
johnny5
string + number causes cat
// What is the return value of the below code sample? Provide a sentence or two of explanation.
99 * "luftbaloons";
NaN
strings can not be multiplied by numbers
// What will the contents of the below array be after the below code sample is executed.
var numbers = [ 2, 4, 6, 8 ];
numbers.pop();
numbers.push( 10 );
numbers.unshift( 3 );
[ 3, 4, 6, 10 ];
.pop causes a removal of the last numer in the array
.push( 10 ) causes an addition of the number 10 to the end of the array
.unshift( 3 ) causes an addition of the number 3 to the front of the array
// What is the return value of the below code sample?
var morse = [ "dot", "pause", "dot" ];
var moreMorse = morse.join( " dash " );
moreMorse.split( " " );
answer before attempting "dotpausedotdash"
i thought join converted all elements of array into a string, and split removed the space between quotes
answer after attempting [ 'dot', 'dash', 'pause', 'dash', 'dot' ]
i re-checked the definition of split... so what i think happened is, split removed the spaces between quotes and then output a new array
// What will the contents of the below array be after the below code sample is executed.
var bands = [];
var beatles = [ "Paul", "John", "George", "Pete" ];
var stones = [ "Brian", "Mick", "Keith", "Ronnie", "Charlie" ];
bands.push( beatles );
bands.unshift( stones );
bands[ bands.length - 1 ].pop();
bands[0].shift();
bands[1][3] = "Ringo";
bands = [[ "Paul", "John", "George", "Pete" ]];
push adds contents of beatles to array
bands = [[ "Brian", "Mick", "Keith", "Ronnie", "Charlie" ], [ "Paul", "John", "George", "Pete" ]];
unshift adds contents of stones to front of array
bands = [[ "Brian", "Mick", "Keith", "Ronnie", "Charlie" ], [ "Paul", "John", "George" ]];
.length - 1 finds the length of the array (9) and subtracts it by 1, which equals 8. pop removes the eighth value of the array
"Brian"
.shift removed "Brian" from the array and returned the string "Brian"
[["Mick", "Keith", "Ronnie", "Charlie" ], [ "Paul", "John", "George", "Ringo" ]];
bands[1][3] = "Ringo" adds "Ringo" to the fourth [3] position of the second [1] array