Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
24 views

Introduction To JavaScript

JavaScript is a scripting language that adds interactivity to web pages. It allows web pages to react to user input and update and change elements on the page. JavaScript code can be embedded directly in HTML files or linked as external files. It uses objects and methods to manipulate HTML elements and run functions in response to events. Common objects include window, document, and navigator, which provide methods to control the browser and access information.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

Introduction To JavaScript

JavaScript is a scripting language that adds interactivity to web pages. It allows web pages to react to user input and update and change elements on the page. JavaScript code can be embedded directly in HTML files or linked as external files. It uses objects and methods to manipulate HTML elements and run functions in response to events. Common objects include window, document, and navigator, which provide methods to control the browser and access information.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Introduction to JavaScript

What is JavaScript?
 JavaScript is a widely used web-based programming language that powers the dynamic
behavior on most websites.
 It was designed to add interactivity and functionality to the web site.

What is Scripting?
 Scripting language means that it is interpreted by another program at runtime rather than
compiled by the computer’s processor as another programing languages are.

Java and JavaScript


 They are two different languages, however, both are influenced by the C language.
 JavaScript is a client-side, high-level scripting, interpreted and object-oriented.

JavaScript Property and Value


 Properties are about the attributes and description of an object.
 You can assign the value to the property of an object by writing:
Objectname.property=values
 Methods are actions that an object can perform.
 You can perform a method by writing:
Objectname.method (parameters)
 Parameters are values or instructions that will be used inside the method.

What can JavaScript Do


 JavaScripts can react to events.
 JavaScript can be used to validate data.
 JavaScript can be used to create cookie.
 JavaScript can enhance a webpage.

Features of JavaScript
 It supports all structured programming syntax in C.
 It has dynamic typing.
 It can run locally on a website.
 It can detect user-action.
 It can be combined with CSS to produce DHTML

Other Features of JavaScript


 JavaScript Can Change HTML
 JavaScript accepts double or single quote. JavaScript Can Change HTML Attributes
 JavaScript Can Change HTML Styles (CSS) –
 JavaScript Can Hide HTML Elements
 JavaScript Can Show HTML Elements

Disadvantages of JavaScript
 Some browsers do not support JS.
 Any secret embedded in JS could be extracted by a determined adversary.
 JS and DOM provide the potential for malicious authors to deliver scripts to run on a client
computer via the web.
 Web Site authors cannot perfectly conceal how their JS operates.
 Source code that have been deliberately made hard to understand can be reverse engineered.

How to start using JavaScript


1. In HTML, JavaScript code must be inserted between <script> and </script> tags.
2. We used the type attribute to define scripting language and identify its version; however, it is
only optional.
3. If the browser does not support JS, it will display JS as page content.

Remember:
 JS is object-based language. Every object has its own method or property.
Example: document.write (“Hi”);
Document is the object name,
Write is the method
Hi is the parameters

Commonly Used Properties /Object and methods under it.


1. window object -The main object.
Sample Methods:
 location –to go to a new location
 open – to open a new window
 setTimeout – to set a time interval before activating an event.
2. document object - Derived from the window object. It is the container for all HTML, HEAD, and
BODY objects associated within the HTML tags of the HTML documents.
Sample methods:
 fgcolor – to set the document foreground color
 cookie – to read the information stored in a cookie text file
 write – to display a message
 lastModified – to display the date it was last modified.
3. math object - Provides the capability to perform math operations.
Sample methods:
 PI – has the value of PI
 pow (a,b) – takes the value of a to the power of b
 max (a, b) – returns the larger value between a and b
 min (a, b) – returns the smaller value between a and b
4. navigator object- Determines which browser is running.
Sample methods:
 appName – to determine the browser’s code name
 appVersion – to determine the browser’s release version
 cookieEnabled – to determine whether cookies are enabled or not.
 platform– a description of the operating system

Function and Event


 Event is the result of a user’s action.
 Event handlers are the way to connect that action to function or a set of JS codes to be
executed.
 Events are objects with properties.
 A JavaScript function is a block of JavaScript code that can be executed when "called" for.
Where can you place Script?
 JavaScript in <head>
 JavaScript in <body>
 Head and Body
<html>
<head>
<script type = “text/JavaScript”>
document.write (“Head Section”);
</script>
</head>
</body>
<script type = “text/JavaScript”>
document.write (“Body Section”);
</script>
</body>
</html>

External JavaScript
 You can place an external script reference in <head> or <body> as you like.
 The script will behave as if it was located exactly where the <script> tag is located.
 External scripts cannot contain <script> tags.
 Use the file extension name .js and src attribute.

Advantages of External JavaScript


 It separates HTML and code
 It makes HTML and JavaScript easier to read and maintain
 Cached JavaScript files can speed up page loads

Comments
 Use // for single line comment
 /* */ for multiple line comments

What are the JS Guidelines?


 JavaScript is case-sensitive.
 Missing and unbalanced quotation marks cause the browser from loading and displaying
improperly.
 Semi-colons at the end of each statement are not required.
 White Spaces- it ignores white spaces as long as it is within the line of the code
 Breaking up of code lines – use back slash (\)

You might also like