JavaScript 1 - Introduction
- Created to “make web pages alive”
- Functioning part of the webpage
- Can write in HTML, executes automatically
- Characteristics
- Full integration with HTML/CSS
- Supported by all major browsers, enabled by default
- Usually runs on client end
- Properties
- Scripting Language
- Enables User Interactions
- Allows for dynamic updating of web content
Usage
- Placed in
- <head>
- <body>
- external .js file
- Seperating HTML and JS code will help manage the code base better
- Designers can work along with coders parallel without code conflicts
- Better readability of HTML and JS
<html lang=”en”>
<head>
<script type="text/javascript">
alert("Welcome to my world!")
</script>
</head>
<body>
<!-- page content -->
</body>
</html>
Basic JavaScript Syntax
Comments
//Single-line comment
/*multi-
line
comment.*/
Lines
document.write("Hello World");
//Lines end in ";"
Case Sensitivity
DOCUMENT.WRITE("Hello World"); //Does not work
document.write("Hello World"); //Works
Keywords
Some words are reserved, such as the ones below.