'자바스크립트'에 해당되는 글 15건

  1. 2008.02.20 JavaScript Functions
  2. 2008.02.20 if else statement, switch statement, operators
  3. 2008.02.20 block, comments, variables
  4. 2008.02.20 JavaScript Where To
  5. 2008.02.13 Introduction to JavaScript - What is JavaScript?

JavaScript Functions

ITWeb/개발일반 2008. 2. 20. 16:22

 
JavaScript Functions
-Functions are first-class objects
-Functions can be passed, returned, and stored just like any other value
-Functions inherit from Object and can store name/value pairs.
-A function is a reusable code-block that will be executed by an event, or when the function is called.
§function functionname(var1,var2,...,varX) {
§ some code
§ or
§ some code
§ return RETURNVALUE;
§}
-function foo() {} expands to var foo = function foo() {}

Inner Functions
-Functions do not all have to be defined at the top level (or left edge).
-Functions can be defined inside of other functions.
-Scope
§    An inner function has access to the variables and parameters of functions that it is contained within.
§    This is known as Static Scoping or Lexical Scoping.
:

if else statement, switch statement, operators

ITWeb/개발일반 2008. 2. 20. 16:12
 
JavaScript If…Else Statements
if ( CONDITION ) {
}
if ( CONDITION ) {
} else {
}
if ( CONDITION ) {
} else if ( CONDITION ) {
}
if ( CONDITION ) {
} else if ( CONDITION ) {
} else {
}


 
JavaScript Switch Statement
switch(n) {
case 1:
execute code block 1
break;
case 2:
execute code block 2
break;
default:
code to be executed if n is
different from case 1 and 2
}

JavaScript Operators
 
Operator
Description
Example
Result
+
Addition
x=2
y=2
x+y
4
-
Subtraction
x=5
y=2
x-y
3
*
Multiplication
x=5
y=4
x*y
20
/
Division
15/5
5/2
3
2.5
%
Modulus (division remainder)
5%2
10%8
10%2
1
2
0
++
Increment
x=5
x++
x=6
--
Decrement
x=5
x--
x=4
 
Operator
Example
Is The Same As
=
x=y
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
 
Operator
Description
Example
==
is equal to
5==8 returns false
===
is equal to (checks for both value and type)
x=5
y="5"
x==y returns true
x===y returns false
!=
is not equal
5!=8 returns true
>
is greater than
5>8 returns false
<
is less than
5<8 returns true
>=
is greater than or equal to
5>=8 returns false
<=
is less than or equal to
5<=8 returns true

 
-&&
§    If first operand is truthy
        then result is second operand
            else result is first operand
-||
§    If first operand is truthy
        then result is first operand
            else result is second operand
Operator
Description
Example
&&
and
x=6
y=3
(x < 10 && y > 1) returns true
||
or
x=6
y=3
(x==5 || y==5) returns false
!
not
x=6
y=3
!(x==y) returns true
 
-String
§txt1="What a very";
§txt2="nice day!";
§txt3=txt1+txt2;
-Conditional
§variablename = (condition) ? value1 : value2;

 
-alert
§var result = alert("sometext");
§alert(result); // undefined
-confirm
§var result = confirm("sometext");
§alert(result); // 확인:true, 취소:false
-prompt
§var result = prompt("sometext", "defaultvalue");
§alert(result); // 확인:string, 취소:null
:

block, comments, variables

ITWeb/개발일반 2008. 2. 20. 15:57
 
JavaScript Blocks
{}
-JavaScript does not have block scope.
-Blocks should only be used with structured statements
§function, if, switch, while, for, do, try
JavaScript Comments
-Single-Line comments : //
-Multi-Line comments : /*…*/
JavaScript Variables
-Variables are "containers" for storing information.
-var keyword is defined local variable.
:

JavaScript Where To

ITWeb/개발일반 2008. 2. 20. 15:54


 
JavaScript Where To
-Scripts in the head section: Scripts to be executed when they are called, or when an event is triggered, go in the head section. When you place a script in the head section, you will ensure that the script is loaded before anyone uses it.
-Scripts in the body section: Scripts to be executed when the page loads go in the body section. When you place a script in the body section it generates the content of the page.
-Scripts in both the body and the head section: You can place an unlimited number of scripts in your document, so you can have scripts in both the body and the head section.
:

Introduction to JavaScript - What is JavaScript?

ITWeb/개발일반 2008. 2. 13. 21:01
얼마전 사내 tech talk 으로 했던 강좌를 공유해 봅니다
기초에서 부터 고급까지 그러나 고급 부분은 맛뵈기구요.
실무 중심의 강좌는 따로 작성 하도록 하겠습니다.

What is JavaScript?
- JavaScript was designed to add interactivity to HTML pages
- JavaScript is a scripting language
- A scripting language is a lightweight programming language
- A JavaScript consists of lines of executable computer code
- A JavaScript is usually embedded directly into HTML pages
- JavaScript is an interpreted language (means that scripts execute without preliminary compilation)
- Everyone can use JavaScript without purchasing a license


: