Quiz 1 Flashcards
Assignment
An operation that takes the single value from the right side and attempts to set that value to the property or variable on the left side
Eg. myVar=10 + 5
Code block
- a section of code that is grouped together
- in JavaScript this would generally refer to a set of statements grouped using curly brackets { }
code compilation
when code is evaluated and translated into one or more code units
code interpretation
when code is parsed statement by statement at runtime
conditional statements
- conditional statements can be used in coding situations where different blocks of statement are executed depending on the conditions at run time
- the two statements covered where: the IF… ELSE statement and the SWITCH statement
conditional statements: if… else
the IF STATEMENT evaluates a condition and executes a block if it’s true
- optionally this is followed by an else part which is for false conditions
- often another if statement is chained to the else part and this is sometimes referred to as an ELSE IF
conditional statements: switch
switch statements are used when a single condition is checked to see if it matches exact values or cases
- the switch is followed by the expression to check, which can be anything that resolves to a single value to check
- CASE statements follow, each should be an exact match for the checked expression
- following the case are the instructions which would generally end with a BREAK that exists in the block
- optionally a final DEFAULT case can be supplied to deal with all left over scenarios
comments
- one or more text lines that are ignored by the interpreter
- can be used to leave developer remarks
- can also be used to temporarily exclude statements from execution
concatenation
- an operation that puts two strings together into one
- e.g. “hello” + “there” = “hellothere”
Data type conversion
- in javascript loosely typed variables can be changed after the fact by:
IMPLICIT CONVERSION: is done by the interpreter as needed. For example a number will convert to a string if passed to a window.alert()
EXPLICIT CASTING: is done by way of a set of specific methods. For example see parseInt() or parseFloat() in the Week 3 and 4 review.
implicit conversion
is done by the interpreter as needed. For example a number will convert to a string if passed to a window.alert()
explicit casting
done by way of a set of specific methods. For example see parseInt() or parseFloat() in the Week 3 and 4 review.
data types
- a declared variable or function return has an underlying datatype which defines the behaviour or potential operations that:
- in JS variables are “loosely typed” meaning the data type can be changed after initial declaration
- There are 7 data types in JS
data type: boolean
- a primitive data type that can only contain a true or false value
- can be explicitly/implicitly converted to:
- 1 or 0 for numbers
- “true or false for strings
data type: number
- a primitive data type that can contain numbers
- all numbers in JS are floating decimal place values even if they appear to be whole numbers
- can be explicitly/implicitly converted to:
- true or false for booleans where any value >=1 is true and <0 is false
- -“100” for strings
- invalid attempted conversions result in NaN (not a number)
data type: string
- a primitive data type for holding character sets of zero or more characters
- strings can be continued using either ‘single quotes’ or “double quotes”
- all other data types can be explicitly/implicitly converted to a string
type: other
- NULL: an abstract type representing a variable that contains no value
- UNDEFINED: an abstract type representing a variable that has no assignment
- SYMBOLS: an abstract type used to wrap existing objects to alter or add to existing members
- OBJECT: used to create custom objects in addition to those provided by the DOM
Depose
a variable is said to be deposed when it is released from memory
document object model
- a cross-platform standardized approach to defining HTML elements
- includes a number of standardized properties and methods (see objects) for these elements. E.g. document.getElementById()
- AKA DOM
ECMAScript
- the European Computer Manufacturers Association standardized scripting specification
- typically considered synonymous with javascript
Escape Sequences
- are used in character strings to tell the interpreter to treat a given character as it’s ASCII value and not as a jacascript character
- Most commonlyused in JS to keep quotes from terminating a string
- e.g. “People often use "your" when they mean"you're" all too often”
would write as People often use “your” when they read “you’re” all too often
events
- a user or system triggered action that in turn can invoke a function or statement
– HTML elements can have EVENT HANDLERS detailed in the tag as attributes with the value being the JS to execute when the event is triggered
– e.g.
Function invocation
- calling a user-defined or DOM function or method by its name
- always followed by the brackets with or without parameters
function parameters
- parameters are one or more values that are passed to a function to allow it to behave differently from invocation to invocation
- function parameters have local scope and are deposed after completion
function returns
- a function can return a single value to the caller upon completion
- this is done using the keyword RETURN followed by the value to return
functions
- a discrete set of instructions contained using the block chaacters { } and given a unique signature (i.e. name) to allow for invocation
- when a process might need to be completed any number of times
- to facilitate collaborative or re-usable code
Literal value
- the explicit usage of a static value in an expression, often just referred to as a literal
– e.g. myVal=10 + 5 … the 10 and 5 are literals
– e.g. myVal= “hello” + strName … “hello” is literal, but strName is not
objects
- a type of data storage unit that may contain a number of pieces of data or have built in functionality (called members)
- PROPERTIES: the data members of a given object
- METHODS : the functions that can be called for a given object
- object properties and methods are commonly called using “DOT NOTATION” using a period to separate the object and the member
- e.g. window.innerWidth … a property that tells the current width of the window
- e.g. window.alert(“hello”) … a method that produces a dialog box
- can also use bracket notation e.g. window[”’
operations
- a single calculation or process defined using:
- OPERATORS: the symbol used to define the operation
- OPERANDS: the values applied to the operation
- the value an operation returns is known as the RESULTANT
operators
- operators are in most cases a single symbol that is used to denote an operation
- operators can be:
- UNARY: expects a single operand which might be on the left or right of the operator depending on the usage (e.g. myVale++ or ++myVal)
- BINARY: expects two operands on either side of the operator
- -TERNARY: expects three operands, in JS there is only the conditional operator
script blocks
- in HTML the tags are used to define a script block
- within this block the rules of the scripting language (default is JS) apply and the client will attempt to interpret the statements contained within
statement
- a single instruction
- can contain multiple nested operations or expressions
- often referred to as a “line of code” although it could span multiple lines
- literally terminated (ending marked) by the semi-colon although the most interpreters will imply the termination
syntax
- the rules for a given language including coding language
variables
- named containers for holding values that might be used in multiple locations
- variable names should be unique to their scope and can either be:
- read and writeable if declared using the VAR keyword
- read-only (aka constant) if declared using the CONST keyword