I’m having issues with steps 5, 8, 12, and 13. It won’t run.
Table of Contents Table of Contents IntroductionJavaScript 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
Although different languages, developers working with other languages 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