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


JavaScript -operateursverwysing


JavaScript-operateurs word gebruik om waardes toe te ken, waardes te vergelyk, rekenkundige bewerkings uit te voer, en meer.


JavaScript-rekenkundige operateurs

Rekenkundige operateurs word gebruik om rekenkunde tussen veranderlikes en/of waardes uit te voer.

Gegewe dat y = 5 , verduidelik die tabel hieronder die rekenkundige operateurs:

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

Vir 'n handleiding oor rekenkundige operateurs, lees ons JavaScript-rekenkundige handleiding .


JavaScript-opdragoperateurs

Toewysingsoperateurs word gebruik om waardes aan JavaScript-veranderlikes toe te ken.

Gegewe dat x = 10 en y = 5 , verduidelik die tabel hieronder die opdragoperateurs:

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

Vir 'n tutoriaal oor opdragoperateurs, lees ons JavaScript-opdragtutoriaal .



JavaScript String Operators

Die + operateur, en die += operateur kan ook gebruik word om stringe aaneen te voeg (byvoeg).

Gegewe dat text1 = "Goed " , text2 = "Môre" , en text3 = "" , verduidelik die tabel hieronder die operateurs:

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

Vergelykingsoperateurs

Vergelykingsoperateurs word in logiese stellings gebruik om gelykheid of verskil tussen veranderlikes of waardes te bepaal.

Gegewe dat x = 5 , verduidelik die tabel hieronder die vergelykingsoperateurs:

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

Vir 'n tutoriaal oor vergelykingsoperateurs, lees ons JavaScript-vergelykingstutoriaal .


Voorwaardelike (ternêre) operateur

Die voorwaardelike operateur ken 'n waarde toe aan 'n veranderlike gebaseer op 'n voorwaarde.

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

Voorbeeld verduidelik: As die veranderlike "ouderdom" 'n waarde onder 18 is, sal die waarde van die veranderlike "stembaar" "Te jonk" wees, anders sal die waarde van stembaar "Oud genoeg" wees.


Logiese operateurs

Logiese operateurs word gebruik om die logika tussen veranderlikes of waardes te bepaal.

Gegewe dat x = 6 en y = 3 , verduidelik die tabel hieronder die logiese operateurs:

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

JavaScript Bitwise Operators

Bisoperateurs werk op 32-bis-nommers. Enige numeriese operand in die bewerking word omgeskakel na 'n 32-bis-getal. Die resultaat word terug na 'n JavaScript-nommer omgeskakel.

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 voorbeelde hierbo gebruik 4 bisse ongetekende voorbeelde. Maar JavaScript gebruik 32-bis getekende nommers.

As gevolg hiervan, in JavaScript, sal ~ 5 nie 10 teruggee nie. Dit sal -6 terugstuur.

~000000000000000000000000000000101 sal terugkeer 11111111111111111111111111111111010


Die tipe operateur

Die tipe operateur gee die tipe van 'n veranderlike, objek, funksie of uitdrukking terug:

Voorbeeld

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

Neem asseblief kennis:

  • Die datatipe NaN is getal
  • Die datatipe van 'n skikking is objek
  • Die datatipe van 'n datum is objek
  • Die datatipe nul is objek
  • Die datatipe van 'n ongedefinieerde veranderlike is ongedefinieerd

Jy kan nie typeof gebruik om te definieer of 'n JavaScript-objek 'n skikking (of 'n datum) is nie.


Die delete Operator

Die delete -operateur vee 'n eienskap uit 'n objek uit:

Voorbeeld

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

Die delete-operateur verwyder beide die waarde van die eiendom en die eiendom self.

Na uitvee kan die eiendom nie gebruik word voordat dit weer bygevoeg word nie.

Die delete-operateur is ontwerp om op voorwerpeienskappe gebruik te word. Dit het geen effek op veranderlikes of funksies nie.

Let wel: Die verwyderingsoperateur moet nie op voorafbepaalde JavaScript-objekeienskappe gebruik word nie. Dit kan jou toepassing ineenstort.


Die in Operator

Die in -operateur gee waar as die gespesifiseerde eienskap in die gespesifiseerde voorwerp is, anders vals:

Voorbeeld

// 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 instansie van Operator

Die instanceof operateur gee waar as die gespesifiseerde objek 'n instansie van die gespesifiseerde objek is:

Voorbeeld

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

Die nietige operateur

Die leemte -operateur evalueer 'n uitdrukking en gee ongedefinieerd terug . Hierdie operateur word dikwels gebruik om die ongedefinieerde primitiewe waarde te verkry, met behulp van "void(0)" (nuttig wanneer 'n uitdrukking geëvalueer word sonder om die terugkeerwaarde te gebruik).

Voorbeeld

<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>