How do you create a function?
Front
Active users
5
All-time users
6
Favorites
0
Last updated
5 months ago
Date created
Nov 16, 2020
Unsectioned
(18 cards)
How do you create a function?
function MyFunction() {
\\Some code goes here.
}
How do you access nested arrays?
You use multiple brackets indicating where you are trying to access. eg.
var MyArray = [[0,1,2,],[3,4,5],[6,7,8]]
var SomeData = MyArray [1][0]
This would set SomeData to be the number 3
How do you append to the end of an array?
Use the push function.
var MyArray = ['a','b','c','d']
MyArray.push(['e','f','g'])
How do you remove something from the beginning of an array?
Use the shift function.
var MyArray = ['a','b','c','d']
MyArray.shift()
that removes that first item in the array so it will look like this.
var MyArray = ['b','c','d']
how do you write a switch statement?
switch(val) {
case 1:
answer="alpha"
break;
case 2:
answer = "beta"
break;
}
return answer;
What is the and operator in and if statement?
&&
e.g.
if (val <=50 && val >= 25) {
return"Yes";
}
Difference Var, Let and Const?
Var can be used anywhere, Let in the scope of where it was created and Const is a variable that can't be changed.
How do you remove something from the end of an array?
Use the pop function.
var MyArray = ['a','b','c','d']
MyArray.pop(])
that removes that last item in the array.
How would you print variable A?
console.log(A)
How do you use quotes inside a string?
Use the \ before the quotation marks. You can also use single quote or tilde when making the string.
What is a ternary operator?
Shorthand for a if statement if one true false condition. e.g.
a == b ? console.log("Yes, they match" ) : consol.log("nope");
How do you make a comment?
// for single line
/* for multiline
Can multiple inputs give the same output in a switch statement?
Yes, by omiting the break and having the answer at the end of the block. e.g.
switch(val) {
case 1:
case 2:
case 3:
answer='Low'
break;
}
What is the or operator in an if statement?
||
e.g.
if (val >10 || val<5) {
return "between";
}
What is a default in a switch statement?
Similar to an else in an if statement and should go at the end.
How do you append to the beginning of an array?
Use the unshift function.
var MyArray = ['a','b','c','d']
MyArray.unshift('First letter')
That adds that first item in the array so it will look like this.
var MyArray = ['First letter','a','b','c','d']
What is a switch statement?
A switch statement is like an if statement but is shorter to write and looks for a strict match (===)
Can arrays be nested?
Yes, like this
var MyArray=[[4,5,6],[13216,1,31]]