IES: JS-deck 1 Flashcards

1
Q

JS background & history

A
  • JavaScript
  • Object-based scripting language
  • the language interpreter is embedded inside web browser software such as:
    1. Google Chrome
    2. Microsoft Edge
    3. Firefox
    4. Opera
    5. Safari
  • JavaScript cannot read or write files for security (exception: cookies (store minimal data))
  • JS also named:
    1. “LiveScript” (initial name)
    2. “JavaScript” (possibly due to the popularity of Sun Microsystem’s Java(little resemblance)) (name widely used)
    3. “ECMAScript” (June, 1997: Ecma international standards organization standardization) (name not widely used)
    4. Not “JScript” (different language altogether)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Brendan Eich

A
  • created JavaScript at Netscape
  • First introduced JS in December of 1995
  • Co-founded Mozilla project
  • Helped launch Firefox
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

JSON

A
  • JavaScript Object Notation
    *
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

IES JavaScript examples-3 key ingredients

A
  1. Language basics-illustrates language mechanics:
  2. Syntax
  3. Keywords
  4. Operators
  5. Structure
  6. Built-in objects
  7. Web page functionality
    * Illustrates the use of the browser’s DOM to provide user interaction
  8. Web applications
    * Illustrates responsive web-based apps
    * Illustrates JSON techniques
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

JS in HTML doc

A
  • included directly: must be between <script> / </script>
  • Doc can include multiple scripts
  • Scripts may be in head or body of document
  • (recommended) place scripts at the body end
  • Place immediately before the </body>: so browser renders webpage before script interpretation
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

JS don’ts

A
  • type="text/JavaScript"in a <script> is NO LONGER NECESSARY as JS is HTML default scripting language
  • DO NOT Include <script> and </script> in an external JS file
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

JS external files

A
  • Written in plain text files given a .js extension
  • Allows several different pages to call upon same script
  • To include in HTML doc, file name is assigned to src of the <script>
  • Script source can be placed in doc head or body
  • browser will treat script as if written directly where script source is placed
  • can make code maintenance easier
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

locating .js file to assign as script source

A
  • Requires script file be in same folder (directory) as HTML doc
    Ex. <script src="external_script.js"> </script>
  • script in adjacent folder: Assign relative path address of file
    Ex. <script src="js/external_script.js"> </script>
  • Script located elsewhere?: assign absolute path file address
    Ex. <script src="https://www.example.com/js/external_script.js"> </script>
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

disable JS

A
  • some content will only appear if JS is disabled in the web browser
  • JS is disabled by including a <noscript> in HTML doc body
    Ex. <noscript>JavaScript is Not Enabled!</noscript>
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

document.getElementbyId( ‘message’ ).innerText = ‘Hello World!’

A
  • JS displays output dynamically writing content into HTML
  • element identified by id attribute
  • innerText specifies text
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

window.alert( ‘Hello World!’ )

A
  • JS displays content in a pop-up dialog box
  • Calls the alert() method
  • Of the window object
  • Displays content specified within the parentheses in a dialog box
    Ex. (This page says
    Hello World!
    OK button (bottom, right-hand corner))
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

” . “

A
  • operator
  • Describes properties or methods of an object
  • “dot notation”
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

console

A
  • provide helpful messages when code error occurs
  • great for debugging code
  • All leading browsers have JS console within developer tools
  • Developer Tools feature-typically accessed: F12
  • Displays output as well as HTML Doc name and line number of source JS code
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

console.log( ‘Hello World!’ )

A
  • displays output in browser’s JS console
  • (when developing in JS and learning the language, displaying here is initially better)
  • Calls the log() method
  • Of the console object
  • Displays content within () in console window
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

document.write()

A
  • Use is generally considered bad practice
  • method that replaces the entire header and body of the web page
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

JS statements

A
  • a series of instructions that compose JS code
  • Generally executed in top-to-bottom order as browser’s JS engine proceeds
  • JS statements often grouped within braces in function blocks
  • Function blocks can be repeatedly called to execute
  • may contain the following:
    1. Keywords words of special significance in JS language
    2. OperatorsSpecial characters -perform an operation on one or more operands
    3. Values text strings come on numbers, boolean (true/false), undefined, and null
    4. Expressions code units-produce single value
    ( JS expression produces a value; JS statement performs an action)
  • Earlier, JS-terminated by semicolon (some coders still prefer this): now, optional except with semicolon-separated list of multiple statements on a single line
17
Q

JS whitespace (tabs & spaces):

A
  • JS interpreter ignores white space
  • use spacing to make code more readable
  • Indent function block statements- improves readability
  • (use space bar to indent (2 spaces) statements) because (tab spacing may be treated differently in text editors)
18
Q

JS syntax

A
  • the rules that govern JS
  • Recognizes two types of values
    1. fixed
    2. variable
  • literals
19
Q

JS fixed values

A
  • a constant: a keyword that defines a variable or pointer as unchangeable
  • Static and cannot change
  • These are often called literals
  • Include:
    1. null
    2. undefined
    3. number literals
    4. string literals
    the booleans:
    5. true
    (or)
    6. false
20
Q

JS variable values

A
  • called variables
  • Used to store data within a script
  • Can be created using the JS “let” keyword
    Ex. “let total” creates a variable named “total”
  • variable can be set value to store using JS assignment operator “=”
    Ex. let total= 300