Intro Flashcards
JavaScript
- a scripting language meaning that it does not need compile
- programming language that provides instructions to a web browser
Ways to include JavaScript in your page
alert(“Hello Everybody”)
-use the script tags and place in the JS methods.
or use the source attribute as long as js file is in the same directory.
src= “alert.js”
Datatypes
-specialized form of information.
-string: sequence of characters
-number: integer and floats
-boolean
-object: represents a group of key/value pairs
-date: represents date/time
-array: represents a collection of data
var arr= [1,’232’,582]
- undefined: value not yet defined
- null; empty value
variable
a temporary storage unit that stores data
ex: var variableName;
JS Naming rules
- follow camelCase convention (start w lower case)
- names must begin w letter, _, or $
- numbers and Unicode escape sequence can be used after the first character
- names are case sensitive
variable value assignment
-use = sign then brackets
examples:
var name = "Jennifer"; var num = 3;
ex: var carSpecs = { numWheels: 4, engine: 'V6', interior: 'cloth' };
Single and multiline comments
single - //
multiline - /*comment */
to print to console
console.log(“”);
creating function
group of block statements
use function keyword:
function talk() { alert("Hello!"); }
talk();
Hoisting
- a variable declared without using the var keyword, makes it available outside of the function
- hoisting is the process of assigning loose variables to the global window object
Creating objects using literal notation
objects are key/value pairs
ex: var Person = { numWheels: 4, property: value, property: value };
OR use objects constructor
ex: var Person = new Object();
dot notation
access properties of an object using a dot
Person.name = “Adam”;
array notation
access properties using brackets
ex: Person[“name”] = “Adam”;
defining a method
a method that is assigned as property of an object
var Person = { givenName: function { //.... } }
this keyword
this keyword refers to the current executing context but outside of it, it refers to the global window object