January 7, 2014, 11:48 am by: adriano
Unknown
GPS location
So now we've covered the first part of code translation.
You should now learn about variables, data types, and functions, but before we do that, you should understand code flow.
We're going to look at functions to convert to code that we'll be working on later in the course. So the first part of our code, function declaration, looks like this.
Here, "function" is an optional keyword that will appear in the function description. The "function" keyword appears at the end of function code, or at a function definition.
For example, the following code looks like this:
var foo = function () { }; v
ar bar = function bar () { };
The variable foo is part of the body of the function.
The bar function is added to the function body. It's called by the function foo and becomes the result of calling bar .
This is code that is very similar to how you would write a function in C++ when calling a function from within a function body from other functions.
The only difference is that we have one additional function called bar . In our example, foo is in the body of our function bar , so we need to add it to our function declaration: function foo () { } function bar () { } The above code uses the function bar , which is just another function.
When the function foo is called, the function bar is called in order to call foo .
So when bar is called, foo is called as well. When bar is finished calling foo, foo is now finished. The above code has a single line that's added to the function body.
That's all that's needed for us to convert the function we've been working on to code in JavaScript.
In order to work on code translation you need to know how JavaScript operates.
So I'm going to look at code that uses variables and some functions.
See you in the next part of our programing course!