Basic_Javascript Flashcards
What are four FAQs about JavaScript?
What is Javascript?
One of the most popular and widely used programming language in the world right now.
It’s growing faster than any other programming languages.
What large companies are building full applications around JavaScript right now?
Nextflix, Walmart and Paypal
Entire applications around Javascript
What is an average salary for a JavaScript developer?
You can work as:
Front End (React, Angular)
Backend (Node.js)
Full Stack (MEAN)
What can you do with Javascript?
We can build many things now.
mobile/web apps
networking apps / chats / video streaming / games
What was JavaScript originally designed for doing?
For a long time, Javascript was used only for building front end interactive web browsers.
But those days are long gone!
Thanks to huge community support and investment and support by Google, Facebook Javascript has changed.
Where was JavaScript originally designed to run?
Javascript was originally designed to run only in browsers.
Every browser has a JavaScript engine:
FireFox: SpiderMonkey
Chrome: v8
Where does Javascript code run?
Browser:
JavaScript Engine
Node:
C++ w/ JavaScript Engine
Both:
Javascript can be run in the browser using the built-in Javascript engine or in Node!
What happened in 2009?
Ryan Daal
Took the open-source Javascript engine in chrome and embedded it into a C++ program.
Called it Node.js
What is node?
Node is a C++ program that includes Google’s V8 Javascript engine.
Now we can run Javascript outside of a browser.
We can pass our code to Node for execution.
What is ECMA script?
ECMA script is just a specification
ECMA is responsible for defining standards
annual release of a specification
ES2015/ES6 defined many new features
What is the difference between ECMAScript and JavaScript?
JavaScript is a programming language that adheres to the standards provided in ECMAScript.
What can we do in Chrome Developer Tools?
Run JavaScript.
Every browser has a JavaScript engine
What is a good IDE for JavaScript?
Visual Studio code - lightweight IDE
What else should we install?
Node - technically don’t need node to run JavaScript but we use node for installing third-party libraries.
It’s good to have node on your machine!
What does ! Tab generate in Visual Studio Code?
Boiler plate HTML
What is the Live Server extension?
A lightweight local server we can use to run JavaScript
What does run with Live Server do?
It opens our browser and allows us to run our applications!
What is best practice for where to put the script section in our HTML page?
The best practice is to put the script at the end of the body section after all existing elements.
What do we want to explain with our comments?
Why’s
How’s
What is a statement?
A piece of code that expresses an action to be carried out
Why is it best practice to put the script after all the elements in the body section?
- The browser parses HTML file top to bottom - if script is in the head, Browser might get busy executing Javascript code and not be able to render elements on-page.
- JavaScript often acts on the elements - If the script is at the end we can be confident all elements have been rendered by the browser. Sometimes third party code requires being placed in the head (this is exception).
What’s a shortcut to bring the browser developer tools?
Option + Command + i
What is separation of concerns?
Separate HTML (content) from Javascript (behavior)
You don’t want to write it in line with HTML.
What is the difference between HTML and JavaScript?
HTML is all about content
JavaScript is all about behavior
- How should your webpage behave?
- What should happen when we hover over an element? Something pops up, something hidden?
How do we execute JavaScript code in node?
Open the terminal
call node filename.js
What is the Integrated Terminal in Visual Studio?
Can run JavaScript using node without explicitly opening our terminal.
What do we use variables for doing?
Storing data temporarily in a computer’s memory
Name of variable - label on data
How do we declare a variable?
Use the “let” keyword
What are variables by default in Javascript?
undefined
How can we declare a string in Javascript?
use single quotes
What are the rules for naming variables?
Use camelCase
Rules:
Cannot be keywords
Use meaningful names
Cannot start with a number
Cannot contain a space or hyphen
variables are case sensitive
declare each variable on a new line
How do we declare a constant in JavaScript?
use the “const” keyword
use it as default choice
What are the two types in JavaScript?
Primitive (Value) Types
Reference Types
What are the primitive (value) types in JavaScript?
String
Number
Boolean
undefined
null
What separates Javascript from other languages?
It’s a dynamic language
What is the difference between a static and dynamic language?
Static:
Declare a variable, the type is set, cannot be changed
Dynamic:
Type can change in runtime
What is a dynamic language?
Type of variable can change at runtime!
How do we clear the console in our browser?
Control + L
What are all numbers in Javascript?
Type number
integer, floating-point, etc. are all type number
What type is null?
Type object
What are the reference types in JavaScript?
Objects
Arrays
Functions
What is an object?
Related variables grouped together
Keys = Properties
What is the object literal syntax?
Curly braces
How can we access an object property?
Dot notation (one way)
default choice
What is bracket notation?
In Javascript, an object is a key-value pair
to access the value can use bracket notation
object [target property] -> value at target displayed
What is the second way to access an object’s members?
Bracket Notation
Pass a string that determines the name of the property
Use this for unknown selection
What are arrays in JavaScript?
A data structure used to represent a list of items
Dynamic
Objects and sizes are dynamic
Can store different types in arrays
Can add/remove items
Arrays in JavaScript are Objects
What are one of the fundamental building blocks in JavaScript?
Functions!
What kind of operators do we have in JavaScript?
What is an expression?
Operations + variables + constants are used to create expressions
expressions are used to create algorithms
Something that produces a value
What type of arithmetic operators do we have in JavaScript?
How does the increment operator work?
How does the decrement operator work?
–x (decrement first, then assign)
x– (assign, then decrement)
How can we use the assignment operator to increment the value by more than one?
What are comparison operators?
returns a boolean
===
(three equal signs)
equality
What is the strict equality operator?
Ensures both operands are of the same type and value
If the two operands are not of equal type
returns false
More precise and accurate
What are lose equality operators?
Converts both operands to the same type
Checks the value only
What is the ternary operator (conditional operator)?
Start with the condition
if evaluate true, use first value
if false, use the second value
What are logical operators?
Operators used to make decisions based on multiple conditions
&& - returns true if BOTH operands are true
|| - returns TRUE if ONE of the operands is true
! - reverses the boolean
What can we use logical operators to do in JavaScript?
Can use logical operators with non-boolean values!
Extremely powerful
How does JavaScript engine interpret non-boolean values in logical operations?
falsy or truthy
What values are falsy?
undefined
null
0
false (boolean)
’ ‘ (empty string)
NaN
How does JavaScript engine evaluate non-boolean logical operands?
If the value is falsy, treats it as a false
if the value is !falsy, treats it as true
runs normal && ! or || operations
What values are truthy?
not falsy (below)
undefined
null
0
false (boolean)
’ ‘ (empty string)
NaN
What is short-circuiting?
JavaScript will stop evaluation
once a truthy value is found
Ex.
false || 1 || 2
returns 1 (truthy)
doesn’t evaluate 2
What is the result of this expression?
OR operator returns true because ‘1’ is truthy
ternary operator executes first statement “hello”