Part 1: JavaScript Basics
2. SYNTAX
2. SYNTAX
-
- 1 / 18
-
Cartes-fiches
Wie ist das JavaScript Gerüst?
<script language="javascript" type="text/javascript">
JavaScript code
</script>
Wie lautet der Code, um in HTML Hello World! zu schreiben?
<html>
<body>
<script language="javascript" type="text/javascript">
document.write("Hello World!")
</script>
</body>
</html>
Wie schreibt man einen Kommentar in HTML?
1. <!-- KOMMENTAR
KOMMENTAR
KOMMENTAR
-->
2. // Kommentar
Wo überall kann ein JavaScript Code platziert werden?
1. <head>...</head> section
2. <body>...</body> section
3. <body>...</body> and <head>...</head> sections.
4. in einem externen File, platziert werden muss der Code in der <head>...</> section.
Wann platziert man ein JavaScript in der <head> section?
falls man will, dass das Skript für jeden Event verfügbar ist!
Wann platziert man ein JavaScript in der <body> section?
falls man will, dass sobald die seite geladen wird, das JS Inhalte auf der Seite generiert.
nennen sie ein beispiel, mit JS im <body> und im <head>
<html>
<head>
<script type="text/javascript">
<!--
function sayHello() {
alert("Hello World")
}
//-->
</script>
</head>
<body>
<script type="text/javascript">
<!--
document.write("Hello World")
//-->
</script>
<input type="button" onclick="sayHello()" value="Say Hello" />
</body>
</html>
nennen sie ein beispiel für ein JS in einem externen File?
<html>
<head>
<script type="text/javascript" src="filename.js" ></script>
</head>
<body>
.......
</body>
</html>
welche datentypen werden in JS verwendet?
1. Numbers, e.g., 123, 120.50, etc.
2. Strings of text, e.g. "This text string", etc.
3. Boolean, e. g. true or false
für was werden variablen gebraucht?
man kann darin daten abspeichern, und sich später mit dem variablennamen darauf beziehen
beispiel für variablen?
<script type="text/javascript">
<!--
var money;
var name;
//-->
</script>
<script type="text/javascript">
<!--
var money, name;
//-->
</script>
mit welchem keyword wird eine variable definiert?
var
Beispiel:
var money;
erklären sie die begriffe
- Global Variables
- Local Variables
Global Variables: kann überall im JSC definiert werden, da globale Gültigkeit
Local Variables: nur innerhalb einer Funktion sichtbar, darin wird sie auch definiert.
nennen sie ein beispiel für eine globale und lokale variable?
<script type="text/javascript">
<!--
var myVar = "global"; // Declare a global variable
function checkscope( ) {
var myVar = "local"; // Declare a local variable
document.write(myVar);
}
//-->
</script>
nennen sie einige reservierte namen für variablen?
abstract
boolean
break
byte
case
catch
char
class
const
continue
debugger
default
delete
do
double
else
enum
export
extends
false
final
finally
float
for
function
goto
if
implements
import
in
Instanceof
int
interface
long
native
new
null
package
private
protected
public
return
short
static
super
switch
synchronized
this
throw
throws
transient
true
try
typeof
var
void
volatile
while
with
welche typen von operatoren werden in JS verwendet?
Arithmetic Operators
Comparison Operators
Logical (or Relational) Operators
Assignment Operators
Conditional (or ternary) Operators
nennen sie die Arithmetic Operators?
1. + (Addition)
2. - (Subtraction)
3. * (Multiplication)
4. / (Division )
5. % (Modulus) - outputs the remainder of an integer division - Ex: B % A will give 0
6. ++ (Increment) - increases an integer value by one
7. -- (Decrement)
nennen sie die logical operators?
1. && (Logical AND)
2. || (Logical OR)
3. ! (Logical NOT )
4.