JS Basics

While there's some dispute as to where the link to your JS should go, Epicodus teaches that we call to our script file in our HTML file by putting

<script src="js/scripts.js"></script>

in the <head> tag. (If you use an off-site script that specifies putting it at the end of your <body> tag, do that instead.) Note that unlike linking to our CSS file, <script> needs to have a closing tag.

Scoping your variables is crucial in Javascript, as it allows us make code that is more secure and more readable. So if you have any attachment to the "var" keyword, best send out your last few love letters to it. "var" is no longer used because it has no scope and can be used anywhere. Teachers will come at you like ninjas if they see "var" or catch any free-roaming variables. Be prepared and do your best to learn const/let and their scope.

When you call a function, the values sent in the () are referred to as arguments (the names of those arguments are referred to as parameters). The order of those arguments? Big deal.

orderOfArguments("pb", "&", "j"); // call function

function orderOfArguments(first, second, third) {
  console.log(first);
  console.log(second);
  console.log(third);
} // would console.log "pb" "&" "j"

When you're naming a variable or function, be sure to name them in camel case. (ie: "nameOfVariable" or "functionName"). No spaces, first letter is lowercase, and then every other word starts uppercase.

If you're looking to return a value from a function, the return statement is your friend. When your code reaches it, it will exit/stop the function it's running and send back whatever you've specified to return (even if it doesn't return anything!).

Methods are amazing tools to arm yourself with (even early on), as they help so much with manipulating data without having to exhaust yourself writing code.

W3Schools has a pretty useful page on JS operators, if you need to remind yourself how to increment or return remainders using them. Aunt Sally will be ecstatic when she hears you've been thinking about her: remember that order of operations is used when calculating. (For example: 2 + 4 * 2 = 10, not 12)

Javascript concepts sometimes require some additional explanation, so check out Intermediate JS for more gems.

Think we're wrong? Come at us!