29.07.2016 Views

front-end-developer_1_

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Front-End-Developer - Level 1<br />

3. 3 + 5 is run.<br />

4. The result of 3 + 5 is returned.<br />

5. The add function <strong>end</strong>s.<br />

Notice our variables names: number1 and number2 . We could have called them n1 and<br />

n2 , and it would have taken less typing. But the name number1 very clearly expresses<br />

what the variable is for, whereas n1 will require another programmer (or your future self,<br />

when you come back to your code in a few months and don't remember exactly how it<br />

works) to figure it out from context. In this example, it would be pretty obvious what n1 is<br />

for. But if you practice choosing descriptive names now and resisting the temptation to<br />

abbreviate, you will be in the habit of doing it when you're writing more complex code where<br />

it matters more.<br />

Summary<br />

Example function:<br />

var add = function(number1, number2) { return number1 + number2; };<br />

add(1, 2);<br />

An argument is what you pass into a function or method; a parameter is a variable that's<br />

assigned to the argument. Above, number1 and number2 are parameters, and 1 and 2<br />

are arguments.<br />

Use descriptive variable names so that your code is easily readable. Don't be tempted to<br />

abbreviate.<br />

Writing functions<br />

116

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!