Representing data with values
Primitive Data Types
- Primitive Data Types
- Number Type
- String Type
- Boolean data type
- Undefined and null
- What are statements?
- Expression Statements
- Compound and Empty Statements
- Declaration Statements
- Conditional statements
- Loop statements
- Jump Statements
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.
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:
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:
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.
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.