20
Introduction to JavaScript Session 8

08. session 08 intoduction to javascript

  • Upload
    phuc-do

  • View
    343

  • Download
    0

Embed Size (px)

Citation preview

Page 1: 08. session 08   intoduction to javascript

Introduction to JavaScript

Session 8

Page 2: 08. session 08   intoduction to javascript

Explain Javasript language Describe client-side and server-side

Javascript Describe build-in function

Objectives

Page 3: 08. session 08   intoduction to javascript

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

Page 4: 08. session 08   intoduction to javascript

SriptingSripting

Scripting refers to a series of commands that are interpreted and executed sequentially and immediately on an occurrence of an event

Page 5: 08. session 08   intoduction to javascript

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.

Page 6: 08. session 08   intoduction to javascript

<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 .

Page 7: 08. session 08   intoduction to javascript

Declaring VariableDeclaring Variable

In Javascript, the var keyword is used to create a variable by allocating memory to it.

Page 8: 08. session 08   intoduction to javascript

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

Page 9: 08. session 08   intoduction to javascript

Data TypesData Types

Page 10: 08. session 08   intoduction to javascript

Primary Data TypesPrimary Data Types

Page 11: 08. session 08   intoduction to javascript

Composite Data TypesComposite Data Types A composite data type stores a collection of

multiple related values, unlike primitive data types.

Page 12: 08. session 08   intoduction to javascript

““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)

Page 13: 08. session 08   intoduction to javascript

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.

Page 14: 08. session 08   intoduction to javascript

Comments Comments JavaScript support two types of comments. There

are: Single - line comments Multi - line comments

Page 15: 08. session 08   intoduction to javascript

Esccap Sequences CharacterEsccap Sequences Character There are multiple escape sequence characters in

Javascript that provides various kind of formatting.

Page 16: 08. session 08   intoduction to javascript

Built –in FunctionBuilt –in Function

Page 17: 08. session 08   intoduction to javascript

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

Page 18: 08. session 08   intoduction to javascript

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

Page 19: 08. session 08   intoduction to javascript

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.

Page 20: 08. session 08   intoduction to 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