You are on page 1of 11

JavaScript Ko Alpha

Javascri pt
JavaScript web o` scripting language oco`o
JavaScript ooo Web page functionality, form validate ooo. server q
communicate ooo octgo_t ot_o`o
JavaScript ooo`o coo`
_o
This is a paragraph.
Javascri pt
JavaScript o` _tt scripting language coco`o
ooca standard language cocqot desktop app mobile phone app
q internet server o_t oooqoq otq_o`o
oco _ _ oOt oco
Javascript co_c o`g ogo`o
HTNL ac CSS
JavaScript Ko Alpha
JavaScri pt oo ?
JavaScript scripting language coco`o
JavaScript HTNL page oto_aco oqto`o
Scri pti ng Language oo ?
scripting language c o`o`o`to`totac programming language cocot script
gto _oto`o
Script o code line ocot compile ooctq link step oo c`_t interprete
ooac execute ooaco`o
JavaScri pt ooo ot o ?
JavaScri pt HTNL desi gner programmi ng tool coto` o
HTNL editor o oqtoc programmer o_o`ot o`oo JavaScript
gtgtgctgct syntax otq language coco`o octoct JavaScript code line
ot HTNL page O O_aco`o
JavaScri pt HTNL mani pul ate ooaco` o
JavaScript HTNL element g content oac. octaco`o
JavaScri pt CSS mani pul ate ooaco` o
JavaScript HTNL element g style oac. octaco`o
JavaScri pt data val i date ooaco` o
JavaScript form g data cgooc data validate ooo otaco`o
JavaScri pt data ot aco` o
JavaScript visitor's computer data otacot retrive ooaco`o
JavaScri pt event oqaco` o
JavaScript cocogc oqgo _q_t O_ogo`o _o user
HTNL element c ao` oooo`cooc
JavaScript Ko Alpha
JavaScri pt q Java o o
JavaScript q Java concept g design go` cqc o`ot
Java (Sun Nicrosystems Ooo ) tqt programming language cocot C C+
+ q o`o
JavaScri pt = ECNAScri pt
ECNA-262 JavaScript g official standard oco`o
JavaScript Netscape Brendan Eich o oqto`o oOto`o Netscape
Navigator (g web browser) 1995 oco`o oO Nocha o`o`o.
q LiveScript o`ot qt JavaScript q_ocoo`o
JavaScript standard industry standard association ECNA 1997 tctoo`o
standard (ECNAScript-262 o`) international !SO standard oc 1998
ogo`o
ECNAScript q development cgqo`o
JavaScri pt oooot o_ o
JavaScript c <script> q <fscript> tag toc gqoOto`o
JavaScript HTNL element manipulate oooot_o`o
JavaScript Ko Alpha
<scri pt> Tag
JavaScript HTNL caO O_o <script> tag oto`
<script> q <fscript> JavaScript oocot ooto oo`o
<script> q <fscript> _t line JavaScript o`, o`o
<script>
alert("Ny First JavaScript");
<fscript>
o` code qto_ooo`ot <script> tag browser oot JavaScript code
oooqo`o otgc execute ooo`o
type="textfjavascript" c_ct_t <script> tag O oc cotgc cotoo
browser ocq HTNL5 o`O_ooo`ot JavaScript default scripting
language oo`o
HTNL el ement mani pul ate o o c t
HTNL element JavaScript qgacogc document.getElementBy!d(id) method
otgo`o qot "id" attribute HTNL element Oto_o`o
ootot id q HTNL element goo`o ot content octo`o
<!DOCTYPE html>
<html>
<body>
<h1>Ny First Web Page<fh1>
<p id="demo">Ny First Paragraph<fp>
JavaScript Ko Alpha
<script>
document.getElementBy!d("demo").innerHTNL="Ny First JavaScript";
<fscript>
<fbody>
<fhtml>
JavaScript web browser excute ooo`o oqg browser HTNL element
id="demo", qooot content (innerHTNL) "Ny First JavaScript" qocto`o
Document Output O o ggt O_ c t
_o <p> element c HTNL document g output O g
gtO_Oto`o
_o
<!DOCTYPE html>
<html>
<body>
<h1>Ny First Web Page<fh1>
<script>
document.write("<p>Ny First JavaScript<fp>");
<fscript>
<fbody>
<fhtml>
JavaScript Ko Alpha
o
document.write() document output O ggtO_oo otgo`o
document.write loading oootq excute ooogc HTNL page coto overwrite
ocoto`o
_o
<!DOCTYPE html>
<html>
<body>
<h1>Ny First Web Page<fh1>
<p>Ny First Paragraph.<fp>
<button onclick="myFunction()">Try it<fbutton>
<script>
function myFunction()
{
document.write("Oops! The document disappeared!");
)
<fscript>
<fbody>
<fhtml>
JavaScript Ko Alpha
JavaScri pt vari abl e t
variables are "containers" for storing information.
Do You Remember Al gebra From School ?
Do you remember algebra from school? x=5, y=6, z=x+y
Do you remember that a letter (like x) could be used to hold a value (like 5), and that you
could use the information above to calculate the value of z to be 11?
These letters are called vari abl es, and variables can be used to hold values (x=5) or
expressions (z=x+y).
Think of variables as names or labels given to values.
JavaScri pt vari abl es
As with algebra, JavaScript variables are used to hold values or expressions.
A variable can have a short name, like x, or a more descriptive name, like carname.
Rules for JavaScript variable names:
variable names are case sensitive (y and Y are two different variables)
variable names must begin with a letter, the $ character, or the underscore character
Both JavaScript statements and JavaScript variable names are case-sensitive.
JavaScript Ko Alpha
Decl ari ng (Creati ng) JavaScri pt vari abl es
Creating a variable in JavaScript is most often referred to as "declaring" a variable.
You declare JavaScript variables with the var keyword:
var carname;
After the declaration shown above, the variable is empty (it has no value yet).
To assign a value to the variable, use the equal (=) sign:
carname="volvo";
However, you can also assign a value to the variable when you declare it:
var carname="volvo";
After the execution of the statement above, the carname will hold the value volvo.
_o
var carname="volvo";
document.getElementBy!d("myP").innerHTNL=carname;
JavaScri pt Data Types
There are many types of JavaScript variables, but for now, just think of two types: text and
numbers.
When you assign a text value to a variable, put double or single quotes around the value.
When you assign a numeric value to a variable, do not put quotes around the value (if you
put quotes around a numeric value, it will be treated as text).
JavaScript Ko Alpha
Re-Decl ari ng JavaScri pt val ues
!f you re-declare a JavaScript variable, it will not lose its value.
Local JavaScri pt vari abl es
A variable declared within a JavaScript function becomes LOCAL and can only be accessed
within that function. (the variable has local scope).
You can have local variables with the same name in different functions, because local
variables are only recognized by the function in which they are declared.
Local variables are deleted as soon as the function is completed.
You will learn more about functions in a later chapter of this tutorial.
Gl obal JavaScri pt vari abl es
variables declared outside a function, become GLOBAL, and all scripts and functions on the
web page can access it.
Global variables are deleted when you close the page.
Assi gni ng val ues to Undecl ared JavaScri pt vari abl es
!f you assign values to variables that have not yet been declared, the variables will
automatically be declared as global variables.
This statement:
carname="volvo";
will declare the variable carname as a global variable (if it does not already exist).
JavaScript Ko Alpha
JavaScri pt Ari thmeti c
As with algebra, you can do arithmetic operations with JavaScript variables:
_o
y=5;
x=y+2;
You will learn more about the operators that can be used in a later chapter of this tutorial.
JavaScri pt Gui del i ne t
Some other important things to know when scripting with JavaScript.
JavaScri pt i s Case Sensi ti ve
A function named "myfunction" is not the same as "myFunction" and a variable named
"myvar" is not the same as "myvar".
JavaScript is case sensitive - therefore watch your capitalization closely when you create or
call variables, objects and functions.
Whi te Space
JavaScript ignores extra spaces. You can add white space to your script to make it more
readable. The following lines are equivalent:
var name="Hege";
var name = "Hege";
JavaScript Ko Alpha
Break up a Code Li ne
You can break up a code line wi thi n a text stri ng with a backslash. The example below will
be displayed properly:
document.write("Hello
World!");
However, you cannot break up a code line like this:
document.write
("Hello World!");
co_ooo Oco`o
Ko Alpha

You might also like