0% found this document useful (0 votes)
24 views

Kratak Pregled Java Script-A: Operatori

This document provides a summary of JavaScript operators, control flow statements, loops, functions, and objects. It discusses various operators like modulus, increment, decrement, bitwise operators, comparison operators, and logical operators. It covers control flow statements like if/else statements and ternary operators. It describes different loop structures like for, while, do/while, break, and continue. It outlines the Date, String, and Cookie objects and their properties and methods. It also discusses event handling, working with multiple windows, and cookies.

Uploaded by

Miljan Jeremic
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

Kratak Pregled Java Script-A: Operatori

This document provides a summary of JavaScript operators, control flow statements, loops, functions, and objects. It discusses various operators like modulus, increment, decrement, bitwise operators, comparison operators, and logical operators. It covers control flow statements like if/else statements and ternary operators. It describes different loop structures like for, while, do/while, break, and continue. It outlines the Date, String, and Cookie objects and their properties and methods. It also discusses event handling, working with multiple windows, and cookies.

Uploaded by

Miljan Jeremic
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 7

KRATAK PREGLED JAVA SCRIPT-A

OPERATORI
Modulus (%)
var1 % var2

12 % 5 = 2.

Increment (++)
var++

or ++var

y = x++
y=++x

Decrement (--)
var--

or --var

y = x-y=--x

Unary negation (-)


-x

Na nivou bita
Operator

Usage

Description

Bitwise AND

a&b

Returns a one in each bit position if bits of both operands are


ones.

Bitwise OR

a|b

Returns a one in a bit if bits of either operand is one.

Bitwise XOR

a^b

Returns a one in a bit position if bits of one but not both operands
are one.

Bitwise NOT

~a

Flips the bits of its operand.

Left shift

a << b Shifts a in binary representation b bits to left, shifting in zeros


from the right.

Sign-propagating
right shift

a >> b Shifts a in binary representation b bits to right, discarding bits


shifted off.

Zero-fill right shift a >>> Shifts a in binary representation b bits to the right, discarding bits
b
shifted off, and shifting in zeros from the left.

Bitwise logical operators

15 & 9 yields 9 (1111 & 1001 = 1001)


15 | 9 yields 15 (1111 | 1001 = 1111)
15 ^ 9 yields 6 (1111 ^ 1001 = 0110)

Logiki operatori
Operator

Usage

and (&&) expr1 &&


expr2

Description
Returns true if both logical expressions expr1 and expr2 are true.
Otherwise, returns false.

or (||)

expr1 || expr2 Returns true if either logical expression expr1 or expr2 is true. If both
are false, returns false.

not (!)

!expr

x += y

x=x+y

x -= y

x=x-y

x *= y

x=x*y

x /= y

x=x/y

x %= y

x=x%y

x <<= y

x = x << y

x >>= y

x = x >> y

If expr is true, returns false; if expr is false, returns true.

x >>>= y x = x >>> y
x &= y

x=x&y

x ^= y

x=x^y

x |= y

x=x|y

Operatori poreenja
Operator

Description

Example

Equal (= =)

Returns true if the operands are equal.

x == y returns true if x equals y.

Not equal (!=)

Returns true if the operands are not equal. x != y returns true if x is not
equal to y.

Greater than (>)

Returns true if left operand is greater than x > y returns true if x is greater
right operand.
than y.

Greater than or
equal (>=)

Returns true if left operand is greater than x >= y returns true if x is greater
or equal to right operand.
than or equal to y.

Less than (<)

Returns true if left operand is less than


right operand.

x < y returns true if x is less


than y.

Less than or equal Returns true if left operand is less than or x <= y returns true if x is less

(<=)

equal to right operand.

than or equal to y.

(condition) ? val1 : val2


status = (age >= 18) ? "adult" : "minor"

KONTROLE TOKA
if (condition) {
statements1
} else {
statements2
}
Primer:
function checkData () {
if (document.form1.threeChar.value.length == 3) {
return true
} else {
alert("Enter exactly three characters. " +
document.form1.threeChar.value + " is not valid.")
return false
}
}

PETLJE

for
for ([initial-expression]; [condition]; [increment-expression]) {
statements
}
Primer:
<SCRIPT>
function howMany(selectObject) {
var numberSelected=0
for (var i=0; i < selectObject.options.length; i++) {
if (selectObject.options[i].selected==true)
numberSelected++
}
return numberSelected
}
</SCRIPT>
<FORM NAME="selectForm">
<P><B>Choose some music types, then click the button below:</B>
<BR><SELECT NAME="musicTypes" MULTIPLE>
<OPTION SELECTED> R&B
<OPTION> Jazz
<OPTION> Blues
<OPTION> New Age
<OPTION> Classical
<OPTION> Opera
</SELECT>
<P><INPUT TYPE="button" VALUE="How many are selected?"
onClick="alert ('Number of options selected: ' +

howMany(document.selectForm.musicTypes))">
</FORM>

while
while (condition) {
statements
}
Primer:
n = 0
x = 0
while( n < 3 ) {
n ++
x += n
}
while (true) {
alert("Hello, world") }

break
function testBreak(x) {
var i = 0
while (i < 6) {
if (i == 3)
break
i++
}
return i*x
}

continue
i = 0
n = 0
while (i < 5) {
i++
if (i == 3)
continue
n += i
}

Switch
switch ( numberthing ) {
case firstval:
statements;
break;
case secondval:
statements;
break;
...
default:
statements;

break;
}
Primer:
function balance(int which) {
String retval=;
switch ( which ) {
case 8:
retval = Good;
break;
case 13:
retval = Not Good;
break;
default:
retval = Error;
break;
}
return(retval);

DATE Objekat
1.
2.
3.
4.

dateObjectName
dateObjectName
dateObjectName
dateObjectName

=
=
=
=

new
new
new
new

Date()
Date("month day, year hours:minutes:seconds")
Date(year, month, day)
Date(year, month, day, hours, minutes, seconds)

Metodi:

getDate
getDay
getHours

getMinutes
getMonth

getSeconds
getTime
getYear
setDate

setHours

setMinutes
setMonth

setSeconds
setTime
setYear
toString

Primeri:
today = new Date()
birthday = new Date("December 17, 1995 03:24:00")
birthday = new Date(95,12,17)
birthday = new Date(95,12,17,3,24,0)
cas=today.getHours()
minuti=today.getMinutes()
sekunde=today.getSeconds()

String Objekat
Property Description
length

Duina stringa

Methodi
big
blink
bold

fontcolor
sup
sub

fontsize
italics
small
strike

indexOf
lastIndexOf
substring

toLowerCase

toUpperCase
charAt

Primer
var last_name = "Schaefer"
last_name.length
last_name.toUpperCase()
last_name.toLowerCase()
last_name.charAt(0)
last_name.indexOf(hae)
last_name.indexOf(e,5)
last_name.lastIndexOf(e)
last_name.lastIndexOf(e,5)
last_name.substring(1,5)
last_name.substring(1,50)

8
"SCHAEFER"
"schaefer"
S
2
6
6
4
chae
chaefer

Obrada dogadjaja
Dogadjaj

Primena na

Kada se pojavljuje

Metod

abort

images

User aborts the loading of an image onAbort


(for example by clicking a link or
clicking the Stop button)

blur

windows, frames, and all form User removes input focus from
elements
window, frame, or form element

onBlur

click

buttons, radio buttons,


checkboxes, submit buttons,
reset buttons, links

User clicks form element or link

onClick

change

text fields, textareas, select


lists

User changes value of element

onChange

error

images, windows

The loading of a document or image onError


causes an error

focus

windows, frames, and all form User gives input focus to window,
elements
frame, or form element

load

document body

onFocus

User loads the page in the Navigator onLoad

mouseout areas, links

User moves mouse pointer out of an onMouseout


area (client-side image map) or link

mouseover links

User moves mouse pointer over a


link

onMouseOver

reset

User resets a form (clicks a Reset


button)

onReset

forms

select

text fields, textareas

User selects form element's input


field

onSelect

submit

submit button

User submits a form

onSubmit

unload

document body

User exits the page

onUnload

<INPUT TYPE="button" VALUE="Calculate" onClick="compute()">


<HEAD>
<SCRIPT>
<!--- Hide script from old browsers
function compute() {
if (confirm("Are you sure?"))
PrvaForma.result.value = eval(PrvaForma.izraz.value)
else
alert("Please come back again.")
}
// end hiding from old browsers
-->
</SCRIPT>
</HEAD>
<BODY>
<FORM name="PrvaForma">
Enter an expression:
<INPUT TYPE="text" NAME="izraz" SIZE=15 >
<INPUT TYPE="button" VALUE="Calculate" onClick="compute()">
<BR>Result:
<INPUT TYPE="text" NAME="result" SIZE=15 >
</FORM>
</BODY>

Cookies
name=value
[;EXPIRES=dateValue]
[;DOMAIN=domainName]
[;PATH=pathName]
[;SECURE]

var citamCookie=document.cookie
document.cookie = name=+vrednostKojuPamtim+;secure

Rad sa vie prozora


deteProz = open(noviProzor.html, deteProz)
deteProz.deteForma.deteObjekat.value
window.opener.document.otacforma.otacObjekat.value

You might also like