JS Reference

JS by Category JS by Alphabet

JavaScript

JS Array JS Boolean JS Classes JS Date JS Error JS Global JS JSON JS Math JS Number JS Operators JS RegExp JS Statements JS String

Window

Window Object Window Console Window History Window Location Window Navigator Window Screen

HTML DOM

DOM Document DOM Element DOM Attributes DOM Events DOM Event Objects DOM HTMLCollection DOM Style
alignContent alignItems alignSelf animation animationDelay animationDirection animationDuration animationFillMode animationIterationCount animationName animationTimingFunction animationPlayState background backgroundAttachment backgroundColor backgroundImage backgroundPosition backgroundRepeat backgroundClip backgroundOrigin backgroundSize backfaceVisibility border borderBottom borderBottomColor borderBottomLeftRadius borderBottomRightRadius borderBottomStyle borderBottomWidth borderCollapse borderColor borderImage borderImageOutset borderImageRepeat borderImageSlice borderImageSource borderImageWidth borderLeft borderLeftColor borderLeftStyle borderLeftWidth borderRadius borderRight borderRightColor borderRightStyle borderRightWidth borderSpacing borderStyle borderTop borderTopColor borderTopLeftRadius borderTopRightRadius borderTopStyle borderTopWidth borderWidth bottom boxShadow boxSizing captionSide caretColor clear clip color columnCount columnFill columnGap columnRule columnRuleColor columnRuleStyle columnRuleWidth columns columnSpan columnWidth counterIncrement counterReset cursor direction display emptyCells filter flex flexBasis flexDirection flexFlow flexGrow flexShrink flexWrap cssFloat font fontFamily fontSize fontStyle fontVariant fontWeight fontSizeAdjust height isolation justifyContent left letterSpacing lineHeight listStyle listStyleImage listStylePosition listStyleType margin marginBottom marginLeft marginRight marginTop maxHeight maxWidth minHeight minWidth objectFit objectPosition opacity order orphans outline outlineColor outlineOffset outlineStyle outlineWidth overflow overflowX overflowY padding paddingBottom paddingLeft paddingRight paddingTop pageBreakAfter pageBreakBefore pageBreakInside perspective perspectiveOrigin position quotes resize right scrollBehavior tableLayout tabSize textAlign textAlignLast textDecoration textDecorationColor textDecorationLine textDecorationStyle textIndent textOverflow textShadow textTransform top transform transformOrigin transformStyle transition transitionProperty transitionDuration transitionTimingFunction transitionDelay unicodeBidi userSelect verticalAlign visibility width wordBreak wordSpacing wordWrap widows zIndex

Web APIs

API Console API Fullscreen API Geolocation API History API MediaQueryList API Storage

HTML Objects

<a> <abbr> <address> <area> <article> <aside> <audio> <b> <base> <bdo> <blockquote> <body> <br> <button> <canvas> <caption> <cite> <code> <col> <colgroup> <datalist> <dd> <del> <details> <dfn> <dialog> <div> <dl> <dt> <em> <embed> <fieldset> <figcaption> <figure> <footer> <form> <head> <header> <h1> - <h6> <hr> <html> <i> <iframe> <img> <ins> <input> button <input> checkbox <input> color <input> date <input> datetime <input> datetime-local <input> email <input> file <input> hidden <input> image <input> month <input> number <input> password <input> radio <input> range <input> reset <input> search <input> submit <input> text <input> time <input> url <input> week <kbd> <label> <legend> <li> <link> <map> <mark> <menu> <menuitem> <meta> <meter> <nav> <object> <ol> <optgroup> <option> <output> <p> <param> <pre> <progress> <q> <s> <samp> <script> <section> <select> <small> <source> <span> <strong> <style> <sub> <summary> <sup> <table> <tbody> <td> <tfoot> <th> <thead> <tr> <textarea> <time> <title> <track> <u> <ul> <var> <video>

Other References

CSSStyleDeclaration JS Conversion


Referenz zu JavaScript -Operatoren


JavaScript-Operatoren werden verwendet, um Werte zuzuweisen, Werte zu vergleichen, arithmetische Operationen auszuführen und mehr.


JavaScript-Arithmetikoperatoren

Arithmetische Operatoren werden verwendet, um Arithmetik zwischen Variablen und/oder Werten durchzuführen.

Da y = 5 ist, erklärt die folgende Tabelle die arithmetischen Operatoren:

Operator Description Example Result in y Result in x Try it
+ Addition x = y + 2 y = 5 x = 7
- Subtraction x = y - 2 y = 5 x = 3
* Multiplication x = y * 2 y = 5 x = 10
/ Division x = y / 2 y = 5 x = 2.5
% Modulus (division remainder) x = y % 2 y = 5 x = 1
++ Increment x = ++y y = 6 x = 6
x = y++ y = 6 x = 5
-- Decrement x = --y y = 4 x = 4
x = y-- y = 4 x = 5

Ein Tutorial zu arithmetischen Operatoren finden Sie in unserem JavaScript-Arithmetik-Tutorial .


JavaScript-Zuweisungsoperatoren

Zuweisungsoperatoren werden verwendet, um JavaScript-Variablen Werte zuzuweisen.

Da x = 10 und y = 5 , erklärt die folgende Tabelle die Zuweisungsoperatoren:

Operator Example Same As Result in x Try it
= x = y x = y x = 5
+= x += y x = x + y x = 15
-= x -= y x = x - y x = 5
*= x *= y x = x * y x = 50
/= x /= y x = x / y x = 2
%= x %= y x = x % y x = 0

Eine Anleitung zu Zuweisungsoperatoren finden Sie in unserem JavaScript-Zuweisungs-Tutorial .



JavaScript-String-Operatoren

Der +-Operator und der +=-Operator können auch zum Verketten (Hinzufügen) von Zeichenfolgen verwendet werden.

Da text1 = "Good " , text2 = "Morning" und text3 = "" , erklärt die folgende Tabelle die Operatoren:

Operator Example text1 text2 text3 Try it
+ text3 = text1 + text2 "Good " "Morning"  "Good Morning"
+= text1 += text2 "Good Morning" "Morning" ""

Vergleichsoperatoren

Vergleichsoperatoren werden in logischen Anweisungen verwendet, um die Gleichheit oder den Unterschied zwischen Variablen oder Werten festzustellen.

Da x = 5 ist, erklärt die folgende Tabelle die Vergleichsoperatoren:

Operator Description Comparing Returns Try it
== equal to x == 8 false
x == 5 true
=== equal value and equal type x === "5" false
x === 5 true
!= not equal x != 8 true
!== not equal value or not equal type x !== "5" true
x !== 5 false
> greater than x > 8 false
< less than x < 8 true
>= greater than or equal to x >= 8 false
<= less than or equal to x <= 8 true

Ein Tutorial zu Vergleichsoperatoren finden Sie in unserem JavaScript-Vergleichs-Tutorial .


Bedingter (ternärer) Operator

Der Bedingungsoperator weist einer Variablen basierend auf einer Bedingung einen Wert zu.

Syntax Example Try it
variablename = (condition) ? value1:value2 voteable = (age < 18) ? "Too young":"Old enough";

Beispiel erklärt: Wenn die Variable "Alter" einen Wert unter 18 hat, ist der Wert der Variable "Wählbar" "Zu jung", ansonsten ist der Wert von "Wählbar" "Alt genug".


Logische Operatoren

Logische Operatoren werden verwendet, um die Logik zwischen Variablen oder Werten zu bestimmen.

Da x = 6 und y = 3 sind, erklärt die folgende Tabelle die logischen Operatoren:

Operator Description Example Try it
&& and (x < 10 && y > 1) is true
|| or (x === 5 || y === 5) is false
! not !(x === y) is true

Bitweise JavaScript-Operatoren

Bit-Operatoren arbeiten mit 32-Bit-Zahlen. Jeder numerische Operand in der Operation wird in eine 32-Bit-Zahl umgewandelt. Das Ergebnis wird zurück in eine JavaScript-Zahl umgewandelt.

Operator Description Example Same as Result Decimal
& AND x = 5 & 1 0101 & 0001 0001  1
| OR x = 5 | 1 0101 | 0001 0101  5
~ NOT x = ~ 5  ~0101 1010  10
^ XOR x = 5 ^ 1 0101 ^ 0001 0100  4
<< Left shift x = 5 << 1 0101 << 1 1010  10
>> Right shift x = 5 >> 1 0101 >> 1 0010   2

Die obigen Beispiele verwenden 4-Bit-Beispiele ohne Vorzeichen. JavaScript verwendet jedoch 32-Bit-Zahlen mit Vorzeichen.

Aus diesem Grund gibt ~ 5 in JavaScript nicht 10 zurück, sondern -6.

~0000000000000000000000000000101 gibt 1111111111111111111111111111010 zurück


Der Typ des Operators

Der typeof -Operator gibt den Typ einer Variablen, eines Objekts, einer Funktion oder eines Ausdrucks zurück:

Beispiel

typeof "John"                 // Returns string
typeof 3.14                   // Returns number
typeof NaN                    // Returns number
typeof false                  // Returns boolean
typeof [1, 2, 3, 4]           // Returns object
typeof {name:'John', age:34}  // Returns object
typeof new Date()             // Returns object
typeof function () {}         // Returns function
typeof myCar                  // Returns undefined (if myCar is not declared)
typeof null                   // Returns object

Bitte beachten:

  • Der Datentyp von NaN ist Zahl
  • Der Datentyp eines Arrays ist Objekt
  • Der Datentyp eines Datums ist Objekt
  • Der Datentyp von null ist Objekt
  • Der Datentyp einer undefinierten Variablen ist undefiniert

Sie können typeof nicht verwenden , um zu definieren, ob ein JavaScript-Objekt ein Array (oder ein Datum) ist.


Der delete-Operator

Der delete -Operator löscht eine Eigenschaft aus einem Objekt:

Beispiel

const person = {
  firstName:"John",
  lastName:"Doe",
  age:50,
  eyeColor:"blue"
};
delete person.age;   // or delete person["age"];

Der delete-Operator löscht sowohl den Wert der Eigenschaft als auch die Eigenschaft selbst.

Nach dem Löschen kann die Eigenschaft nicht verwendet werden, bevor sie wieder hinzugefügt wird.

Der delete-Operator ist für die Verwendung mit Objekteigenschaften konzipiert. Es hat keine Auswirkung auf Variablen oder Funktionen.

Hinweis: Der Löschoperator sollte nicht für vordefinierte JavaScript-Objekteigenschaften verwendet werden. Es kann Ihre Anwendung zum Absturz bringen.


Der in-Operator

Der in -Operator gibt true zurück, wenn sich die angegebene Eigenschaft im angegebenen Objekt befindet, andernfalls false:

Beispiel

// Arrays
const cars = ["Saab", "Volvo", "BMW"];
"Saab" in cars          // Returns false (specify the index number instead of value)
0 in cars               // Returns true
1 in cars               // Returns true
4 in cars               // Returns false (does not exist)
"length" in cars        // Returns true  (length is an Array property)

// Objects
const person = {firstName:"John", lastName:"Doe", age:50};
"firstName" in person   // Returns true
"age" in person         // Returns true

// Predefined objects
"PI" in Math            // Returns true
"NaN" in Number         // Returns true
"length" in String      // Returns true

Die Instanz von Operator

Der Operator instanceof gibt true zurück, wenn das angegebene Objekt eine Instanz des angegebenen Objekts ist:

Beispiel

const cars = ["Saab", "Volvo", "BMW"];

(cars instanceof Array)   // Returns true
(cars instanceof Object)  // Returns true
(cars instanceof String)  // Returns false
(cars instanceof Number)  // Returns false

Der Leere-Operator

Der Operator void wertet einen Ausdruck aus und gibt undefined zurück . Dieser Operator wird häufig verwendet, um den undefinierten primitiven Wert mit "void(0)" zu erhalten (nützlich, wenn ein Ausdruck ausgewertet wird, ohne den Rückgabewert zu verwenden).

Beispiel

<a href="#;">
  Useless link
</a>

<a href="javascript:void(document.body.style.backgroundColor='red');">
  Click me to change the background color of body to red
</a>