JavaScript/CheatSheet: Difference between revisions

From Wiki
(Die Seite wurde neu angelegt: „== Data Types == <pre> var num = 8; // number var strg = "Joe"; // string var vobj = {first: "John", las…“)
 
mNo edit summary
Line 50: Line 50:
>>          Right shift
>>          Right shift
>>>        Zero fill right shift
>>>        Zero fill right shift
</pre>
== if - else ==
<pre>
if (condition) {
    // if condition is met
} else {
    // if condition is not met
}
</pre>
== Loops ==
<pre>
for
while
do while
break
continue
</pre>
== Escape Characters ==
<pre>
\'      Single quote
\"      Double quote
\\      Backslash
\b      Backspace
\f      Form feed
\n      New line
\r      Carriage return
\t      Horizontal tabulator
\v      Vertical tabulator
</pre>
</pre>

Revision as of 20:09, 24 December 2021

Data Types

var num = 8;                               // number
var strg = "Joe";                          // string
var vobj = {first: "John", last:"Doe"};    // object
var booli = false;                         // boolean
var arr = ["HTML","CSS","JS"];             // array
var a; typeof a;                           // undefined
var a = null;                              // value null

const pi = 3.14;

Strings



Operators

+           Addition
-           Subtraction
*           Multiplication
/           Division
(...)       Grouping operator, operations within brackets are executed earlier than those outside
%           Modulus (remainder )
++          Increment numbers
--          Decrement numbers

==          Equal to
===         Equal value and equal type
!=          Not equal
!==         Not equal value or not equal type
>           Greater than
<           Less than
>=          Greater than or equal to
<=          Less than or equal to
?           Ternary operator

&&          Logical and
||          Logical or
!           Logical not

&           AND statement
|           OR statement
~           NOT
^           XOR
<<          Left shift
>>          Right shift
>>>         Zero fill right shift


if - else

if (condition) {
    // if condition is met
} else {
    // if condition is not met
}

Loops

for
while
do while
break
continue

Escape Characters

\'      Single quote
\"      Double quote

\\      Backslash
\b      Backspace
\f      Form feed
\n      New line
\r      Carriage return
\t      Horizontal tabulator
\v      Vertical tabulator