Technical Documentation Page - Build a Technical Documentation Page

Tell us what’s happening:
Having issues with 3, 4, 7, 12, and 13. They’re not running.

Table of Contents Table of Contents Introduction
JavaScript and Java
Hello World


Declaring Variables

Variable Scope

The End




Introduction

An introduction to the front end programming language JavaScript and JavaScript.

Java is used primarily

  • For mobile applications
  • For desktop applications

JavaScript is used primarily for

  • Web application development.
  • In addition to HTML and CSS
  • Creating and controlling content and multimedia
JavaScript and Java

Although different languages, developers working with other langauges often find Java easy to pick up as syntaxes are similar.

JavaScript is an optional element of web design. However, it is an invaluable tool.



Hello World

Hello World is the first pop-up students typically learn to write.

To get started with writing JavaScript, open the Scratchpad and write your first "Hello world" JavaScript code:


function greetMe(yourName) { alert("Hello " + yourName); }
greetMe(“World”);


Declaring Variables

You use variables as symbolic names for values in your application. The names of variables, called identifiers, conform to certain rules.

A JavaScript identifier must start with a letter, underscore (_), or dollar sign ($); subsequent characters can also be digits (0-9). Because JavaScript is case sensitive, letters include the characters “A” through “Z” (uppercase) and the characters “a” through “z” (lowercase).

You can use ISO 8859-1 or Unicode letters such as å and ü in identifiers. You can also use the Unicode escape sequences as characters in identifiers. Some examples of legal names are Number_hits, temp99, and _name.





Variable Scope

You can declare a variable in three ways: With the keyword var. For example,


var x = 42.

This syntax can be used to declare both local and global variables.

By simply assigning it a value. For example,


x = 42.

This always declares a global variable. It generates a strict JavaScript warning. You shouldn't use this variant.

With the keyword let. For example,


let y = 13

The End

When you declare a variable outside of any function, it is called a global variable, because it is available to any other code in the current document. When you declare a variable within a function, it is called a local variable, because it is available only within that function. JavaScript before ECMAScript 2015 does not have block statement scope; rather, a variable declared within a block is local to the function (or global scope) that the block resides within. For example the following code will log 5, because the scope of is the function (or global context) within which x is declared, not the block, which in this case is an if statement.

if (true) { var x = 5; } console.log(x); // 5

Your code so far

To display your code in here you need to wrap it in triple back ticks. On a line by itself type three back ticks. Then on the first line below the three back ticks paste in your code. Then below your code on a new line type three more back ticks. The back tick on my keyboard is in the upper left just above the Tab key and below the Esc key. You may also be able to use Ctrl+e to automatically give you the triple back ticks while you are typing in the this editor and the cursor is on a line by itself. Alternatively, with the cursor on a line by itself, you can use the </> button above the editor to add the triple back ticks.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.