This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function shouter(whatToShout) { | |
return `${whatToShout.toUpperCase()}!!!`; | |
} | |
/* From here down, you are not expected to | |
understand.... for now :) | |
Nothing to see here! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function computeArea(width, height) { | |
return width * height; | |
} | |
/* From here down, you are not expected to | |
understand.... for now :) | |
Nothing to see here! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function main() { | |
try { | |
doAllTheThings(); | |
} | |
catch(e) { | |
console.error(e); | |
reportError(e); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function accessFirstItem(array) { | |
return array[0]; | |
} | |
function accessThirdItem(array) { | |
return array[2]; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function firstFourItems(array) { | |
return array.slice(0, 4); | |
} | |
function lastThreeItems(array) { | |
return array.slice(-3); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Variable scope can be defined as how the variables you declare either can or cannot be accessed at different points in your code. | |
With global scope, any variable that is declared outside of a Javascript function has global scope. | |
Inside Javascript functions are local scopes and with the scope chain, Javascript follows the scope chain to determine the value of the variable. | |
Global variables are avoided because they tend to make unintended side effects more likely. | |
Also, global variable along with unintended side effects almost guarantee that the code becomes indeterminate, meaning | |
given a single set of inputs, returns one value sometimes and another at other times. | |
Whenever Javascript's strict mode is enabled, anytime a variable is declared without const or let, an error will be triggered. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function keyDeleter(obj) { | |
delete obj.foo; | |
delete obj.bar; | |
return obj; | |
} | |
var sampleObj = { | |
foo: 'foo', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function fizzBuzz(countTo) { | |
// your code here | |
var values = []; | |
for (var i = 1; i <= countTo; i++) { | |
if (i % 5 === 0 && i % 3 === 0) { | |
values.push('fizzbuzz'); | |
} | |
else if (i % 5 === 0) { | |
values.push('buzz'); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const studentData = [ | |
{ | |
name: 'Tim', | |
status: 'Current student', | |
course: 'Biology' | |
}, | |
{ | |
name: 'Sue', | |
status: 'Withdrawn', | |
course: 'Mathematics' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getTokens(rawString) { | |
// NB: `.filter(Boolean)` removes any falsy items from an array | |
return rawString.toLowerCase().split(/[ ,!.";:-]+/).filter(Boolean).sort(); | |
} | |
The getTokens function is a regular expression which is a sequence of characters that forms a search pattern. | |
The lower case method will return all the words in text in lower case form. | |
The regular expression is being used to search for all the punctuation marks in text such as [,!.";:-]+ and | |
is then using the split method to split the array into an array of substrings, returning a new array. | |
As noted above, the .filter(Boolean) is being used to remove any falsy items from an array. |
OlderNewer