JavaScript

Ace your homework & exams now with Quizwiz!

Function Constructor

var myFunction = function (a, b) {return a * b};

call site

+ is the line of code where zero or more arguments are passed to the function + A.K.A. callback

logical assertions

* An assertion is a statement that evaluates to either true or false * Used in combination with `if` and `else`, logical assertions allow us to write conditional logic into our programs.

object

* a complex data type may combine different types of data * nameOfObject = { key:value pairs }

TypeScript

* an open-source programming language developed and maintained by Microsoft. * Strictly written; offers many errors *compiled into regular javascript to be rendered in broswer

event listeners

An event listener consists of two parts. First you have to specify which event to listen for. Second, you have to provide a callback function that runs whenever the event occurs.

JSON

JavaScript Object Notation- a serialized version of javascript *All that means is it's a way that we can represent a JavaScript object as a string that can be transmitted between a server and client. Web APIs provide JSON data, and we write JavaScript client code that translates JSON back into in-memory JavaScript objects.

arguments

Set values to the functions parameters. They are passed in during the callback.

data types

The kind of value that the variable holds: + string (text) + object + number + boolean + null + undefined

new Keyword

Variables declared with new keyword makes an object Avoid String, Number, and Boolean objects. They complicate your code and slow down execution speed.

JavaScript

a programming language- the only one available in All modern browsers included in HTML: <script src="app.js"></script>

modulus operator (%)

finds the remainder after division of one number by another

map

new identical lenghth but with different elements

web API

provides endpoints, which are URLs that we can make requests to in order to write or retrieve data

block scope

when a variable is defined within a function...only available within that function

=; ==; ===;

= --> Assignment Operator == --> Equals to === --> Strictly equal to; equal value and equal type

3 ways to declare a variable

* let=> variable who's value can (but doesn't need to be) reassigned -------------------------------------------------------- * const => variable with a CONSTANT value...can't be reassigned -------------------------------------------------------- * var => similar to let, value can be reassigned, different from `let` in terms of variable scope. Might use it because it is supported in all browsers.

Logical Operators

&& logical and || logical or ! logical not

built in array methods

* .push (add item to end of array) * .length (gives number of items in array) * .pop (removes the final item from an array & returns the discarded item) * .map (used to create a new array from existing array by going over an array and applying same function to each item) EX= function double(num) { return 2 * num; }

logical operators

* == -SIMPLE EQUALITY * === -STRICTER, APPLIES TO BOOLEAN TRUTHINESS * && -LOGICAL and * || -OR * ! -NOT * <= -less than or equal to * >= -greater than or equal to * !== -not equal to

function

* A function is a mini program that you define only once in your code and invoke or call elsewhere. * A repeatable process or behavior. -------------------------------------------------- function sayHello(personName) { const greeting = "Hi there, " + personName; console.log(greeting); }

Class based programming

* A.K.A class-orientation * A style of object-oriented programming (OOP) * Inheritance is achieved by defining classes of objects

variable

* containers for storing data values. * They give us a way to manage STATE....the way values persist over time in a program. *variables declare space in memory to store values

state

* has to do with persisting values over time in a program *the state of a program is defined as its condition regarding stored inputs

conditionals

* used to CONTROL FLOW (along with try/catch/finally blocks) * To use a conditional, begin with the command (if, else, else if), followed by an expression wrapped in parentheses (true === true). Between the curly brackets ({...}) comes the statement(s) to be executed if the expression evaluates to true. ---------------------------------------------------

for loops

* used to run through a set of instructions a specific number of times. const countTo = 10; for (let i = 1; i <= countTo; i++) { console.log(i); }

accessibility profiling

**figuring out where our accessibility shortcomings are, & knowing why a particular choice is bad for users, and how that choice can be improved * aXe is chrome extension to profile the accessibility of webpages/apps and report back the a11y violations.

array

*Arrays are used to store lists of items in JavaScript. List items can be of different types, and can even be other lists (arrays). * const emptyArray = []; const nonEmptyArray = [1, 'two']; * Array contents are accessed by index — you can access an item in an array by asking for the item in a given position in the array.

Global scope/variables

*when variables are declared outside of a function * variables declared globally can even be called from other files *can have unintended side effects

Anonymous Function

+ A function without a name. + However, they can contain only a single executable statement. + They are always invoked (called) using the variable name. + Ends with a semicolon because it is a part of an executable statement.

White Space

+ JavaScript ignores multiple spaces. + Add white space to your script to make it more readable. * A good practice is to put spaces around operators ( = + - * / )

Function Hoisting

+ JavaScript's default behavior of moving declarations to the top of the current scope. + Applies to variable and function declarations. + Because of this, functions can be called before they are declared + Functions defined using an expression are not hoisted.

Keywords

+ identify the JavaScript action to be performed break = Terminates a switch or a loop continue = Jumps out of a loop and starts at the top debugger = Stops the execution of JavaScript, and calls (if available) the debugging function do ... while = Repeats the block, while a condition is true for = Marks a block of statements to be executed, as long as a condition is true function = Declares a function if ... else = A block of statements to be executed, depending on a condition return = Exits a function switch = Marks a block of statements to be executed, depending on different cases try ... catch = Implements error handling to a block of statements var = Declares a variable

control flow

Control flow dictates how programs execute different sets of instructions based on differing conditions. You might have one branch that executes if a condition is true, and another that executes if it's false.

3 ways to create a Function

Function Expression: let add = function() { console.log("add stuff"); } ==================================== Function Declaration: function add() { console.log("add stuff"); } ===================================== Arrow Function: let add = () => { console.log("add stuff"); }

Code Blocks

Groups together javascript statements with curly brackets { ...} Defines statements to be executed together.

Class-based language

PHP, C++, Java, C#, and Objective-C.

Where is the correct place to insert a JavaScript?

Scripts can be placed in the <body>, or in the <head> section of an HTML page, or in both. * Placing scripts at the bottom of the <body> element improves the display speed, because script compilation slows down the display.

variable scope

a set of rules that define which parts of your code can access a particular variable. It's what allows us to reuse variable names at different points in our code, without things breaking.

AJAX

asynchronous JavaScript & XML request *refers to making calls to the server after the page has initially loaded

identifiers

required; unique names given to variables Rules: Names can contain letters, digits, underscores, and dollar signs. Names must begin with a letter Names can also begin with $ and _ (but we will not use it in this tutorial) Names are case sensitive (y and Y are different variables) Reserved words (like JavaScript keywords) cannot be used as names JavaScript identifiers are case-sensitive.

Filter

takes a predite funtion makes smaller array

concatenate

to connect.....use the `+` operator

special character escaping

used to "escape" quotation marks ------------------------------------------------ const heSaid = "He said, \"Foo!\""; console.log(heSaid); // => He said "Foo!" ------------------------------------ \n is used for new line.... *whole list on https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String#Escape_notation


Related study sets

Chapter 10: Interest Groups and Lobbying

View Set

Exam 2 - Ch. 8, 9, 10, 11, 12, 13, 14

View Set

PSI National Exam for Real Estate

View Set

Q2 Cumulative Test Review (U.S History)

View Set

Quiz 11 Burns and Emergency/Trauma

View Set

Concept 3: Periodic table of elements

View Set

MGMT 4350 Chapter 9: Ethics, Corporate Social Responsibility, Environmental Sustainability

View Set