- Create an array containing the following strings:
"zebra", "giraffe", "elephant"
.
var animals = ["zebra", "giraffe", "elephant"]
-
Save the array you created above to a variable
animals
. -
using the array
animals
, how would you access"giraffe"
?
console.log(animals[1]);
- How would you add
"lion"
to theanimals
array?
console.log(animals.shift("lion"));
- Name and describe two additional array methods.
- unshift: method used to add new element(s) to the beginning of an array
- shift: method used to remove an element from the beginning of an array
- What are the boolean values in JavaScript?
Boolean values in JavaScript are like a "light switch" - they signal if - is true or false and are used when you want to set conditions to allow a (part of a) script to run or not.
- In JavaScript, how would you evaluate if
2
is equal to25
? What is the result of this evaluation?
console.log(2 === 25); // return false
- In JavaScript, how would you evaluate if
25
is greater than2
? What is the result of this evaluation?
console.log(25 > 2); // return true