CheatSheets
Some Basic
Comments
There are two types of comments: // this is a single line comment /_ this is a multiple line comment when you have to write a lot of things _/
// Single line commentlet name = "John";/*muliptle line commentline comment.Somecase also use disable code parts*/let fullname = "Doe";let age = 35;
Variables
Variables – values that hold data to perform calculations or other operations
- var - most widely used. can be accessed within the function where declared. can be reassigned.
- const – constant value i.e. cannot be reassigned
- let – can be used only within the block its declared, can be reassigned
Data types
Can be of different types
- Number, eg.
var id = 20
- Unassigned variable, eg.
var x
- String, eg.
var company = “hackr”
- Boolean, eg.
var windowopen = true
- Constants. eg.
const counter = 1
- Operations, eg.
var sum = 20 + 20
- Objects, eg.
var student =
Contains single object of various data types
Arrays
Arrays group similar kinds of data together. Eg, var subjectlist = [“math”, “science”, “history”, “computer”];
More info: https://www.w3schools.com/js/js_arrays.asp
Arrays can perform the following functions:
More info:
https://www.w3schools.com/js/js_array_methods.asp
https://www.w3schools.com/jsref/jsref_obj_array.asp
Functions | Description |
---|---|
concat() | Concatenate different arrays into one. |
join() | Joins all the elements of one array as a string |
indexof() | Returns the index (first position) of an element in the array |
lastindexof() | Returns the last position of an element in the array |
sort() | Alphabetic sort of array elements |
reverse() | Sort elements in descending order |
valueof() | Primitive value of the element specified |
slice() | Cut a portion of one array and put it in a new array |
splice() | Add elements to an array in a specific manner and position |
unshift() | Add new element to the array in the beginning |
shift() | Remove first element of the array |
pop() | Remove the last element of the array |
push() | Add new element to the array as the last one |
tostring() | Prints the string value of the elements of the array |
Operators
Basic
- Addition
+
- Subtraction
-
- Multiply
*
- Divide
/
- Remainder
%
- Increment
++
- Decrement
--
- Execute brackets first
…
Logical
- And
&&
- Or
||
- Not
|
Comparison
- Equal to
==
- Equal value and type
===
- Not equal
!=
- Not equal value or type
!==
- Greater than
>
- Less than
<
- Greater than or equal to
>=
- Less than or equal to
<=
- Ternary operator
?
Bitwise
- AND
&
- OR
|
- NOT
~
- XOR
^
- Left shift
<<
- Right shift
>>
- Zero fill right shift
>>>
continue later from here: https://hackr.io/blog/javascript-cheat-sheet#download-javascript-cheat-sheet