Sie sind auf Seite 1von 10

javaScript

-consule is a very useful tool to check out your errors.


-external file of the css file :

<link rel=stylesheet href=file.css>

Internal file:<style>,,,,,</style>

-external file of the javaScript file (itd be better to put it after the
css external file) :

<script src=.js></script>

Internal file: <script>,,,,</script>

-javascript code can be put in the head or the body of the html code

-javascript external file should be put before the body closing tag

-to write a comment in javascript : //comment

-to write a multiline comment in javascript : /* comment */

-when you write many variables together:

Var x=3,

Y=4,

Z=9;

-camel case search for it on google

Variables:
-name of variable must start with underscore _ or letters or signs
never with numbers and the name must be written with the camel
case system.

-the variable need to have a value:

Var variable name assignment operator value of the variable

Data type:

-Boolean = true or false

-array=[nameto seprate between multiple names use common=


,]

-object = {camel case name: value}

-string=name or name

You can write double quotes within single quotes and vice versa

my name is bahia

-numbers are written directly

-concatenation is a different way to link between strings with + and


you can add another space between strings by adding an empty
string: +stringName

to make an operation between a string name you must put the


operation between brackets : (1+2+3) + bahia+(5+6) = 6bahia11

You can link also between variables with that way

Output:

-alert(value) its a way to make something pups up at the beginning


of the loading page
-document.write(value) its better to use it only for testing because
its going to be so confusing later on

-document.getElementById(the defined Id name from the html


element).innerHTML= value

-console.log(value) the value appears only in the console page

Operators:

( -) (+) (=) (*)(/)(%) you can use the counter +++++ to add something
endless to the element

Conditional operators : to compare between two values < or> <=


equal or lower

Assignment operators:

(=) value

(==)if the value of the element__= is value= it is used for


comparision or to make a condition in values

(===) identical operator it is a way to compare data tye with value

Logical operators:

(!) not equal

(!=) not equal the value

(!==)it is not equal the value and neither the data type

(&&)and

(l l ) or
Functions:

Fuction name of the function must be written with the variable


name rules () {the method}

-the variables within the function method must be defined to call it

Events:

To set an action before loading the page you need to create an


event:

- window.onload = function () {}

To set an action when clicking on certain area you need to create :

- window.onclick = function () {}

To set an action when double clicking on certain area you need to


create:

- window.ondblclick = function () {}
- You can create an event without the window code by writing to
function description within the opening tag of the element in
html: <button event=functionName()>
- You can create many events at once , in the opening tag of the
html element and describe it within the script sheet
- Onkeyup will start doing the function when you leave the press
- Onkeydown will start doing the function when you press enter
- Onmouseover will do the event when you hover with the
mouse on item
- Onmouseout will do the event when you leave hovering with
the mouse on item
- Onchange is an event that keeps up with your changes
according to your next change

Arrays:

Its a collection of saved groups that have the same


perspectives
Var name = new array()
Name [0] = new name
Name [1] = new name
Name [2] = new name
Name [3] = new name
Or
Var name = new array(

new name,
New name,
New name, !!!!!!new names are elements
New name,
)
Literal way to write arrays codes :
Var name = [
new name,
New name,
New name,
New name,
]
- To get the length of your array by creating:
console.log(name.length ) it will show up in the console

- the length always is bigger than the index number with 1 , the
index starts with zero but length with 1
- you can set the number of the arrays length by creating:
name.length = number

- to change an array into a string: name = name.join(write the


punctuation between each element)
- to add another array element: name[index number or you can
write : name.length when you dont know exactly the element
index ]=new name
- you can add an element to the array directly at the end of the
list by creating : name.push(new name)
- you can add an element to the array directly at the begenning
of the list by creating : name.unshift(new name)

- to add an element according to your needs you can use this


code: arrayName.splice(index, how many items you will take
out after the index num, item1,item2)

- in order to order the items of the array you need to write :


arrayname.sort() and it will order the items according to the
alphabetic if its a string or by number order if its a number
and if you want to do the opposite order use this code:
arrayname.reverse()

- to slice arrays into parts : var slicesName =


arrayName.slice(index start num,index end num) you can use
negative num if you want to start the counting the opposite
way

note!!! : the staring index in the opposite way is -1


- to combine between arrays you need to create this code :

var newArrayName = arrayName.concat(the other arrayName,


the second other arrayName.)

- if you want to use a special parameters on one of the array


elements like adding new perspectives setting events and
functions you use this code to call the item from the array :
var newNameOfTheItem = arrayName.indexOf(you can write
the string itself or the number of the index)
- you can use the same codes for string editing instead of arrays
Loops:
- for loop syntax : for(starting value ;condition definition to run
the loop ;final expression which executed every time the code
runs ){ statement : the action }
- for ( variable in object ) {

object.hasOwnProperty( variable ){

statement

-syntax while:

starting value: you need to define it as a variable

While(condition){

statement ;
final expression which executed every time the code runs;

Do while syntax:

starting value: you need to define it as a variable

Do {

Statement ;

final expression which executed every time the code runs;

} While(condition)

- the difference between while condition and do while condition


is that : while condition starts with the condition and then
executes the action but do while condition starts with
executing the action and then setting the condition
- you can control the loop also by adding if statement to the loop
and the statement within the if is:
Break :its a way to cut the loop in a certain point
continue: its a way to delete an item from the loop without
effecting the loop execution
- you can create different loops at once by adding another
for/do while/while statement within the first one
- you can name different loops by adding before the statement:
loopName:
thats a very useful way to specify your next action if you have
many loops
Math:
- Math.ceil(x) = its a function which will look for the closest
number to x up ;example : x= 4.6 =5 is the closest up number to
x
- Its opposite is Math.floor(x)= its a function which will look for
the closest number to x down ;example : x= 4.6=4
- Math.round(x)=
- Math.random()= is a way in which you can set random items
Regular expression:
- The syntax :
Var. search /replace/ match/split/test(/pattern/attribute/)
- We have some very useful codes to specify your needs by
adding after the pattern : i = means case insensitive so that
when your browser looks for the items it doesnt care about
capital or small letters
g= Global search so the browser will look
for the item in the whole codes
- Brackets use: []look for certain character

[^]look for everything except this character

[x-y]look for the characters within this range

[^x-y] look for everything except this range

If statement:

Das könnte Ihnen auch gefallen