JavaScript:~ basics Part 2

Welcome back!

In previous part we dicussed about variables, constants and functions. Those were the pretty basic constructs of JavaScript. They create the base of what we are going to learn next.

Obviously, in any program we just don’t stick with defining variables and functions. We do something with it. Every program defines a logic. A logic can be a simple math working out a formula and generating results. For example, calculating the area of cirle:

function areaOfCirle (radius) {
     const PI = 3.14;
     var area = PI * radius * radius;
     return area;
}
areaOfCirle(14);

Or, it can be DOM manipulation such as updating sections of HTML page. DOM manipulation and updating HTML page can be tricky topic to discuss for now as the tutorial is designed for beginners. Hence, we will drop it and cover it later (once we are comfortable with the rest of JavaScript).

Wondering where to run all this code we are writing?

Don’t go anywhere! A tool is available right in your browser window.

If you are on a windows or linux platform, press F12. This will open up the developer tools for the browser. Developer’s tools are used for debugging HTML sites. It also provides you with a console window where you can type and test your JavaScript code on the fly.

Go to the “console” tab and copy-paste the code written above. Press enter and you will see the results.

For Mac platform you can press Command + Shift + C or Command + Shift + J to open developer’s tool.

Let’s continue with our programming and this time we will create a program that uses a condition.

 

Advertisements

1 thought on “JavaScript:~ basics Part 2

  1. Pingback: JavaScript:~ basics | Speed JS

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s