0% found this document useful (0 votes)
4 views

JavaScript

This document provides an overview of JavaScript, highlighting its interaction with the DOM, variable types, and rules for naming. It explains functions, their usage, and includes examples of mathematical operations and string manipulation methods. Additionally, it mentions resources for practicing JavaScript skills, such as repl.it and mks.io/js101.

Uploaded by

AnnaKarenina25
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

JavaScript

This document provides an overview of JavaScript, highlighting its interaction with the DOM, variable types, and rules for naming. It explains functions, their usage, and includes examples of mathematical operations and string manipulation methods. Additionally, it mentions resources for practicing JavaScript skills, such as repl.it and mks.io/js101.

Uploaded by

AnnaKarenina25
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

Notes for JavaScript:

Very important: JS works directly with DOM

JavaScript: Node.js

Used for: Animations, event handling, dynamic and static pages

web browswer read javaScript: top/bottom, left to right

works as input/output system

JS types:

variables: a pointer, an arrow that points to a memory storage space

var myName = "Patrick"

Rules for variable names:


- must start with a letter or underscore
- no space
- are case sensitive

Examples:
var myName
var x5
var hi_there

the firs word is lowercase


the firs letter is always capitalized

referencing variables:
math operators:
addition:
var x = 22
var y = 4
var z = x+y
z = 26

subtraction:
z = x - y
z = 16

multiplication and division follow the same logic

Order of operations:
(+ x - /) + x - /

repl.it = it allows to see how your code work without opening in a text editor

Functions:
where all the magic happens
- to stow routines
has two uses:
- executing a particular task
- computing and returning a value
- They run when they're invoked
format:

var myFunction = function (){


code
}

practical use of a function. Example:

var makeSeven = function () {


return 6 +1
}

to invoke:
var calculation = makeSeven ()

Function arguments: arguments allow the function to play with outside data
var myFunction = function (arguments){
code to be executed
}

calling on a function with arguments:


var myFunction = function (arg1, arg2, arg3){
>> arg 1, 2 and 3 can be referenced here!
var x = arg + arg
}

pratical use:
var computeProduct = function (num1, num2){
return num1 * num2
}

var product = computeProduct(2,4)

JS proprietary library:
math.random():
returns a random decimal between 0.00 and 1.00

uses: games

Math.round ()
it returns a round version of the number
Math.round(4.7)
returns 5

Math.floor(4.7)
returns 4

Math.max(number, ..., ...)


returns the largest of the numbers passed in

Math.max(23, 45, 16)


returns 45

Math.power(base, exponent)
Math.power(2, 4)
returns 16
MDN: Ms. Eich, who created java script, is also the creator of Mozilla, therefore
Mozilla Developer Network

JS: string manipulation

method length:
input:
var myName = "John"
myName.length

output:
4

concatenation:
combining strings, or other variables

var firstName = "John"


var lastName = "Doe"
var fullName - firstName + "" + lastName

console.log(fullName);

.slice(start)
creates a copy that has a prototype linked to it
input:
"MakerSquare".slice(5)
output:
"Square"
is the equivalent of crop in CorelDraw

Mark website for exercises:


mks.io/js101

alwaysbecommitting

You might also like