Why JAVASCRIPT?
How to write and run Javascript
How to Add Javascript to Webpage
Representing data with values
Primitive Data Types
- Primitive Data Types
- Number Type
- String Type
- Boolean data type
- Undefined and null
- JavaScript Type Conversions
Operators
Expressions
Statements
- What are statements?
- Expression Statements
- Compound and Empty Statements
- Declaration Statements
- Conditional statements
- Loop statements
- Jump Statements
- Assignments
Arrays
If you are considering learning how to code, Javascript is a great choice.
You probably already have all the tools you need:
– a notepad application
Any text editor will do, including the standard Windows Notepad (Start menu/All programs/Accessories/Notepad).
– a web browser
You can run/test your programs in any browser: Chrome, Firefox, Internet Explorer, Safari, Edge, Opera etc.
That’s it! Other languages may require you to download and install a compiler or an entire development environment; others may require setting up an account to access an online programming environment. But you don’t need any of these things to learn Javascript (I’ll be using the acronym JS from now on).
First let me show you a step-by-step example proving how easy it is and then I’ll tell you why I think JS is such a great programming tool.
1. Type the following in your notepad:
<script>
alert(‘Hello world’);
</script>
It should look similar to this:
The first line marks the beginning of JS code for the browser.
The second line is the actual program – it tells the browser to display a popup window (‘alert’) with the words’Hello world’.
The last line marks the end of the JS code.
2. Save this text somewhere on your hard drive, eg. on the desktop.
In the ‘file name’ field, type in:
hello.html
Change the ‘Save as type’ from ‘Text documents’ to ‘All files’:
Note that we used ‘.html’ as the file extension. That tells the browser that our file is a web page (HTML to be more precise, but don’t worry if you don’t know what it means) and the browser should execute the script included in the file.
If you save the file with the default ‘.txt’ extension, the browser will just display the code (just like notepad), instead of executing it.
3. Open the file in your web browser. You can either:
– drag the icon from your file manager window onto the browser window or
– use the browser’s ‘Open’ command from the menu or using the Ctrl+O keyboard shortcut
The browser will ask you which file should be opened. Locate the ‘hello.html’ that you just created and doubleclick on it.
Congratulations! You should see your first JavaScript program running in your browser:
The popup boxes look slightly differently in different browsers.
Of course this is a very simple example, but I hope it convinces you that the JS development cycle is very easy.