Basic JavaScript Info

Basic JavaScript Info

memorize.aimemorize.ai (lvl 286)
Section 1

Preview this deck

What does bind do on an object function?

Front

Star 0%
Star 0%
Star 0%
Star 0%
Star 0%

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Active users

0

All-time users

0

Favorites

0

Last updated

6 years ago

Date created

Mar 1, 2020

Cards (60)

Section 1

(50 cards)

What does bind do on an object function?

Front

Create a new instance of the function but change the context of the this statements in the function to the parameter passed. let newFunction = o.getID.bind(newCar);

Back

Determine if a variable is not a number

Front

Number.isNaN(myVar);

Back

"abc" > "ZYX"

Front

True Lower case has precedence over upper case

Back

Method to call in constructor if inheriting properties from another class

Front

super()

Back

Destructuring Array let carIds = [1,2,5] Assign carId1, carId2, and carId3 to these elements

Front

let [carId1,carId2,carId3] = carIds;

Back

JavaScript will initialize variables to _________ let myNewVar;

Front

undefined

Back

Creating and exporting a class using a module

Front

In a separate file export class myClass{...}

Back

Include a css stylesheet in html

Front

<link rel = 'stylesheet' type='text/css' href='mysheet.css'>

Back

Create a new array of cars with only red cars. Use arrow function

Front

let redCars = myCars.filter(car => car.color == 'red');

Back

What does continue keyword do in loop?

Front

Immediately ends current loop and iterates again. No more code is run for that current block

Back

let o = { cardId: 123, getID: function(prefix,postfix){ console.log(prefix + this.cardId + postifx)}} let newCar = { carId: 456 } Use apply function to run the getID function with newCar context

Front

o.getID.apply(newCar,['ID: ', ' for car'])

Back

Does JavaScript support extends for classes?

Front

Yes

Back

Change text of div with id 'myId' to 'Hello World'

Front

var myDiv = document.getElementById('myId') myDiv.innerText = 'Hello World'

Back

let o = { cardId: 123, getID: function(){ console.log(this.cardId)}} let newCar = { carId: 456 } Use bind to create a new function with newCar as the context for this in getID

Front

let newFunction = o.getID.bind(newCar);

Back

let o = { cardId: 123, getID: function(){ console.log(this.cardId)}} let newCar = { carId: 456 } Use call function to run the getID function with newCar context

Front

o.getID.call(newCar);

Back

BOM

Front

Browser object model

Back

Common Built-in JavaScript objects

Front

Math, Date, String, Number

Back

let year = "1967"; console.log(-year);

Front

-1967

Back

IIFE

Front

Immediately invoked function expressions Calling the function immediately after declaring it (function(){console.log('hi')})() Used for closures

Back

Importing a class from a module

Front

import { myClass } from './myFolder/myClass.js'

Back

let year = 1967; console.log(++year);

Front

1968

Back

What are call and apply?

Front

Changing to context of the this keyword to what is passed when calling a function on an object. Apply allows for parameters to be passed as well myObj.runFunction.call(newObject) myObj.runFunction.apply(newObject,[param1,param2])

Back

Get if button is clicked with jquery

Front

$('#myButton').click(function(){})

Back

CSS Preprocessor

Front

An extension of the CSS language that adds variables, functions, and many other techniques. Example: Less

Back

Where does stylesheet go in html?

Front

in <head>

Back

Loop through all car objects in array, printing out car names and index of that car using arrow function

Front

myCars.forEach((car,index) => console.log(car + index));

Back

Create an arrow function with prefix and suffix parameters that prints PREFIX is great with SUFFIX

Front

let myFunction = (prefix,suffix) => prefix + 'is great with' + suffix; OR let myFunction = (prefix,suffix) => {return prefix + 'is great with' + suffix;}

Back

Type of undefined variable

Front

Undefined

Back

Can you change properties of an object when you pass that object to a function?

Front

Yes

Back

Get and remove first element of an array

Front

array.shift();

Back

Ensure that all car objects in myCars array is red. If not print false.

Front

let allRed = myCars.every(car => car.color === 'red');

Back

The window object

Front

The global object in JavaScript. Console and alert is on this

Back

Rest Parameters

Front

Hold multiple values as passed to the function function displayCars(...allCarIds){...} displayCars(100,200,300,250)

Back

Find the first red car object in an array of cars

Front

let car = myCars.find(car => car.color === 'red');

Back

Get if button is clicked without jquery

Front

var element = document.getElementById('myButtonId'); element.addEventListener("click",function(){}); OR <button onclick="doSomething">

Back

Type of null variable

Front

object

Back

Create a constructor function to create a car with an id property

Front

function Car(carId){ this.carId = carId; } let myCar = new Car();

Back

What is a framework for html?

Front

When http request is made to a server, a framework is in the middle. It performs advanced operations and then returns HTML that was requested. Examples: PHP, JAVA, ASP.NET MVC, WordPress.com

Back

Where to add scripts to the DOM

Front

In body, above </body> tag

Back

Get style of element without jquery

Front

var element = document.getElementById('myId'); element.style.display = 'block'

Back

Interpreted language (scripting language)

Front

A language that is run one statement at a time by another program called an interpreter. It doesn't need to be compiled Python, Javascript, C#.

Back

Create javascript class car with constructor that sets car id

Front

class Car{ constructor(carId){this.carId = carId} } let myCar = new Car(12);

Back

setTimeout

Front

Calls a function or evaluates an expression after a specified number of milliseconds setTimeout(function(){ ... },1000}

Back

let year = "1967"; console.log(typeof(+year));

Front

Number

Back

let trackCar = function(carId, city){...} Change default city parameter to New York

Front

let trackCar = function(carId, city = "New York"){...}

Back

setInterval

Front

Calls a function or evaluates an expression at specified intervals (in milliseconds) setInterval(function(){ ... },1000}

Back

let year = 1967; console.log(year++);

Front

1967 year is now 1968

Back

Add JavaScript file to DOM

Front

<script src = 'myScript.js'>

Back

Destructuring Objects let myObject = { id:1, name:'llama'} Assign id to variable myId and name to variable myName

Front

let { myId, myName } = myObject

Back

Remove second element from an array

Front

array.splice(1,1)

Back

Section 2

(10 cards)

get the url location you are pointing to

Front

location.href

Back

HTTP Post with jQuery

Front

import $ from 'jquery'; let promise = $.post(url,user); promise.then( data=> console.log(data); error=> console.log(error); )

Back

Settle a promise

Front

promise.then( value => console.log(value); error => console.log(error); );`

Back

jquery change css of div

Front

.css()

Back

clearInterval

Front

Clears a timer set with setInterval()

Back

Create a new error in a try block

Front

try{ throw new Error('My new error') }

Back

XHR

Front

XMLHttpRequest An alternative to jquery requests (more low level and typically not used)

Back

jquery change inner text of div

Front

.text()

Back

Create a new promise

Front

let promise = new Promise( function(resolve,reject){if(a)resolve('this worked')else reject('this failed')} )

Back

HTTP GET with jQuery

Front

import $ from 'jquery'; let promise = $.get(url); promise.then( data=> console.log(data); error=> console.log(error); )

Back