Reading notes for Code Fellows!
JavaScript allows us to make web pages more interactive and responsive based on four abilities it possesses:
To create a script , we start with a big picture of what we want to achieve and then break it down into smaller tasks. Creating a script can be broken down into three general steps:
Code Each Step
Computers think programmatically. Simply stated, they follow a series of explicit step-by-step instructions to solve a problem. Successful programmers often develop the ability to “think like a computer”, which better enables them to write directions for one.
An expression results in a single value. There are basically two types of expressions:
var color = 'beige';
var area = 3 * 2;
or var gamma = alpha * beta;
Expressions rely on operators to create a single value from multiple values. The types of operators are:
var this = 'that';
the =
is the operator+
-
/
*
++
--
%
+
and it combines or concatenates two strings.
greeting = 'Hi ' + 'Molly';
makes the value of greeting = ‘Hi Molly’NaN
, or ‘Not a Number’Functions are a series of statements grouped together into a single block that instruct the browser to perform a certain task. A function must be declared or defined. having declared a function we can then call that function any time we want the computer to perform that task.
Declaration of a function requires the function keyword, a function name, also called an identifier, we designate, possibly a list of parameters the function requires and a series of one or more statements located inside curly brackets. to perform the given task. An example might be:
function sayHello() {
document.write('Hello!');
}
sayHello
is the function’s namedocument.write('Hello!);
is the statement the function will executeIf a function requires specific information in order to perform its task, there will be a list of parameters inside the () following the function’s name. For instance, in the case of getArea(width,height)
, the getArea function would need the values for width and height supplied to it in order to execute its task. When we supply this information is is known as passing arguments into the function. In the case above, we would pass in values for width and height.
Finally, by including the return
keword in the statements of the function we can have the called function return a value and then exit the function, ignoring any subsequent statements remaining in the block.