Download - 08. session 08 intoduction to javascript
Introduction to JavaScript
Session 8
Explain Javasript language Describe client-side and server-side
Javascript Describe build-in function
Objectives
Javascript is a language that allows you build dynamic and interactive Web pages .Javascript is a scripting language developed by Sun Microsystems and Netscape.Javascript developed from Netscape’s LivescriptClient application run in a broswer such as Netscape Navigator or Internet Explorer and Firefox
Introduction
SriptingSripting
Scripting refers to a series of commands that are interpreted and executed sequentially and immediately on an occurrence of an event
SriptingSripting Client side Scripting: Refer to a script being executed
on the client’s machine by the browser. Server side Scripting: Refer to a script being executed
on Web server to generate dynamic HTML pages.
<SCRIPT> Tag<SCRIPT> Tag The <SCRIPT> tag defines a script for an HTML
page to make them interactive There are two main purpose of the <SCRIPT> tag,
which are: Identifies a given segment of script in the HTML
page. Load an external script file .
Declaring VariableDeclaring Variable
In Javascript, the var keyword is used to create a variable by allocating memory to it.
RulesRules Javascript is a case-sensitive language. These rules are that a variable name: Can consist of digit, underscore, and alphabets. Must begin with a letter or underscore character Cannot begin with a number and cannot contain
any punctuation marks. Cannot contain any kind of special characters
such as +,*,%,and so on. Cannot contain spaces Cannot be a Javascript keyword
Data TypesData Types
Primary Data TypesPrimary Data Types
Composite Data TypesComposite Data Types A composite data type stores a collection of
multiple related values, unlike primitive data types.
““null “ Keywordnull “ Keyword The null keyword specifies that a variable does
not hold any value. (the null value is not equal to zero because zero is a calculate value while null refers to the absence of a value)
Methods to displayMethods to display Javascript allows you to display information
using the methods of the document object . The document object is a predefined object in
Javascriptwrite () : display any type of datawriteln(): Display any type of data and appends a new line character.
Comments Comments JavaScript support two types of comments. There
are: Single - line comments Multi - line comments
Esccap Sequences CharacterEsccap Sequences Character There are multiple escape sequence characters in
Javascript that provides various kind of formatting.
Built –in FunctionBuilt –in Function
JavaScript KeywordsKeywords are predefined terms that can not be used as an object name, function name or variable name
JavaScript Keyword
break case comment
continue default delete
do else export
for function if
import in Label
new return switch
this typeof var
void while with
Build-in FunctionsFunction Description Example
toFixed Specifies the number of digits to be displayed after the decimal point
var price = 23.456;var fixedprice = price.toFixed(2)return 23.46
toPrecision Specifies the number of digits to be displayed from a given number
var price = 45.9431alert(price. toPrecision(3))return 45.9
toString Convert any value into a string value
var age=25;alert(‘Age:’ + age.toString()+’years’)Return Age: 25 years
Summary The Javascript runtime engine reads and
executes the Javascript code either on the server or in the browser.
The Server element includes JavaScript code, which is executed by the Web Server.
The NOSCRIPT element specifies the alternate content to be displayed, if the browser closes not support Javascript.
Summary… Javascript provides various keywords: break, if,
continue, new, this… The toFixed() function that specifies the number
of digits to be displayed after the decimal point. The toPrecision() function specifies the number
of digits in a number to be displayed to the user. The toString() function transforms a value into
string.
Building Dynamic Websites/Session 1/ 20 of 16