Professional Documents
Culture Documents
The Websites You Often Visit, Rely On Javascript To Make Their Content Come Alive
The Websites You Often Visit, Rely On Javascript To Make Their Content Come Alive
• respond to events
• make animations
•…
JS
Some good code editors:
• Sublime Text
• Notepad++
JS
Variables provide a way of labeling data with a descriptive name
JS
To name a variable:
JS
Functions enable you to write code that can be reused over and over again
JS
Conditional Statements:
JS
if statement:
if(condition){
execute these statements;
}
JS
if/else statement:
if(condition){
do something;
}
else{
do something else;
}
JS
Conditional operators:
JS
Operator True if
if(condition){
....
} else if(condition) {
….
} else if(condition) {
….
} else if(condition) {
….
} else {
….
} JS
Switch Statement:
switch (/*variable*/ ){
case 1:
/*execute these statements*/; break;
case 2:
/*execute these statements*/; break;
default:
/*execute these statements*/;
}
JS
Loops cycle through a section of code as long as some condition is met
• for loops
• while loops
• do…while loops
JS
Syntax of for loop:
JS
Timers:
JS
setTimeout:
setTimeout(function, delayInMilliseconds)
JS
setInterval:
setInterval(function, delayInMilliseconds)
JS
You Browser Is Busy:
requestAnimationFrame(someFunction)
JS
Variable Scope:
JS
Global Scope:
JS
Local Scope:
JS
Where to put JavaScript :
JS
Commenting your code:
If you can’t tell what you’re code is doing, then it’s USELESS !!
JS
Comments help you understand what the code is doing
JS
Best Practices For Commenting:
• Comment clearly
• Don’t over-comment
JS
Booleans( true or false), numbers, strings are called types.
JS
JavaScript is hiding something !!
JS
Types
String Null
Number Undefined
Boolean Object
Types can be either primitives or they can be complex.
JS
Did you say Object ?!
JS
Predefined Objects
String Number
Boolean Array
Date Math
Finding characters:
JS
Finding characters:
JS
Splitting a string:
You can also split a string apart using the split method.
JS
Arrays:
An array stores a sequence of values that are all of the same type.
JS
Putting Objects Under the Microscope:
JS
Creating an Object:
JS
Immediately Invoked Function Expression:
JS
IIFE are used:
• In closures
JS
Document Object Model:
JS
<!DOCTYPE html>
<html>
<head>
<title>This is a title</title>
</head>
<body>
<div>
<p>Some text <a>and a link</a></p>
</div>
</body>
</html>
The window object represents the browser window
JS
The document object represents your web page
JS
Selecting elements in the DOM:
JS
Styling Content:
#parent {
width: 100px; <div id="parent"></div>
height: 100px;
padding: 10px;
border: 2px solid black;
}
JS
You can use JavaScript to style your elements !!
JS
Styling approaches:
JS
classList API:
JS
Creating and inserting elements:
2. Assign attributes to it
3. Insert it
JS
Events are actions that occur when the user or the browser
manipulates a page. For example: clicking a button, pressing a key …
JS
Event Triggered when
JS
The Event Object:
JS
Retrieve pressed keys:
• keyup event
• keydown event
• keypress event
JS
Forms:
JS
CONGRATULATIONS !!
JS
Thanks!
You have a question ? Let’s discuss it below.
What do you think about this course? I would love to hear your feedback.
JS