Javascript Flashcards
Javascript supports what type of style?
object-oriented, functional, and event driven
How is JavaScript executed client-side?
Each browser has a JavaScript engine that || !interprets! || the code
Internal definition
-JS in HTML file
-Imbedded in script tags
-In head or body
-Executed once parsed
window.alert("Test");
External definition
- Script in a .js file
- Script tags
- In header or body
- Executed once parsed
Javascript types
Primitive: -number -string -boolean -undefined Complex -object (inc arrays) -function
type can be checked with typeof(var);
What does JSON stand for?
JavaScript Object Notation
Conversion between JSON and JavaScript
var obj = {name: “Grischa”, age: 31}; //Object
var json = JSON.stringify(obj); //JSON
var json = ‘{“name”: “Grischa”, “age”: “31”}’; //JSON String
var obj = JSON.parse(json); //Object
JSON.stringify() removes functions
Parts of the bad rep of JS covered in VEFF1
Type conversion
Comparators
Scope
Hoisting
JS type conversion
Types are dynamic
Type conversion is from left to right.
var m = 5 + 6 + '5'; m = '115'
JS Comparison
== compares the value, so it does type conversion (!=)
=== compares both the type and value (!==)
JS Scopes
Global, local, and block scope
global/local scope var x = 'bla'
JS Hoisting
JS “hoists” (moves) variable declarations to the top of the scope
JS Calback
Used to execute functionality after work is done.
Callback function is provided as a function parameter
Callback function is caled when main function is finished.
Why use Callback functions
Good tool to use when dealing with the internet, you fx dont know how long an HTTP response takes. No need to check for results. You can continue doing stuff while you wait for the callback function!
AJAX (Asynchronous JavaScript And XML) why and what?
BTW it allows more than just XML, inc JSON.
Allows HTTP requests and responses after the page has been loaded.
Update the page without reload
Load only what is needed
Load different data depending on user actions
Use the standard XMLHttpRequest object to make requests.