// Global Scope
// Local Scope
Scope pollution is when we have too many global variables that exist in the global namespace, or when we reuse variables across different scopes. Scope pollution makes it difficult to keep track of our different variables and sets us up for potential accidents. For example, globally scoped variables can collide with other variables that are more locally scoped, causing unexpected behaviour in our code.
{}.function reportingForDuty(rank, lastName) {
return `${rank} ${lastName} reporting for duty`;
} // format string
function calculateWeight(earthWeight, planet) {
switch (planet) {
case 'Mercury': return earthWeight * 0.378; break;
case 'Venus': return earthWeight * 0.907; break;
case 'Mars': return earthWeight * 0.377; break;
case 'Jupiter': return earthWeight * 2.36; break;
case 'Saturn': return earthWeight * 0.916; break;
default: return 'Invalid Planet Entry. Try: Mercury, Venus, Mars, Jupiter, or Saturn.';
}
}
trueOrFalse = value => value ? true : false;
function sillySentence(str1, str2, str3) {
return `I am so ${str1} because I ${str2} coding! Time to write some more awesome ${str3}!`;
}