JavaScript

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

*javascript-if* What are the three logical operators?

&& (logical and) | | (logical or) ! (logical not)

*javascript-arrays* What number represents the first index of an array?

0

*javascript-methods* Roughly how many array methods are there according to the MDN Web docs?

40

*javascript-methods* Roughly how many string methods are there according to the MDN Web docs?

50

*javascript-if* Give 6 examples of comparison operators.

== is equal to === strict equal to != is not equal to > greater than < less than =< less than or equal to

*Javascript-timers* What is a "callback" function?

A callback function is a function passed into another function as an argument, which is then invoked inside the outer function to complete some kind of routine or action.

*javascript-custom-methods* What is a method?

A method is a function which is a property of an object.

*javascript-methods* What is a method?

A method is a property of object.

*javascript-operators-and-expressions* What data type is returned by an arithmetic operation?

A number value

*javascript-functions* What is the difference between a parameter and an argument?

A parameter is a local variable to a function. We declare a couple of variables, and then when arguments are passed to them, they store those values from the arguments inside of the local variables and then we can use those variables in order to access the values that were passed in these arguments.

*javascript-operators-and-expressions* What is string concatenation?

A process of taking two or more strings to create one new string.

*javascript-objects* Describe object literal notation.

A variable and an opening curly brace and a collection of properties and values.

*javascript-custom-methods* What are the four "principles" of Object-Oriented Programming?

Abstraction, Encapsulation, Inheritance, Polymorphism

*javascript-ajax* What is AJAX?

Ajax is part of the conceptual idea of us being able to make asynchronous requests for outside data from a server and use it to dynamically update our websites without having to refresh the entire page.

*javascript-custom-methods* What does API stand for?

Application programming interface.

*javascript-arrays* How are arrays different from "plain" objects?

Arrays are numerically indexed so they have numerical values that are assigned as their indexes their prosperity names essentially, while in contrast, an object has a series of key value pairs that are created whatever names you want for those properties to be.

*javascript-ajax* What does the AJAX acronym stand for?

Asynchronous JavaScript and XML.

*javascript-and-json* Why are serialization and deserialization useful?

Because it allows us to transfer objects through a network by converting it into a byte stream, and the other way too.

*javascript-custom-methods* What is "abstraction"?

Being able to work with (possibly) complex things in simple ways.

*javascript-primitives-and-variables* What is the purpose of a boolean?

Boolean represents true or false values and we can use those in things like conditional statements in order to make decisions in our code. True or false represent one of two values either true being on false being off.

*javascript-if* What data type do comparison expressions evaluate to?

Boolean value

*javascript-operators-and-expressions* What data type is returned by comparing two values (<, >, ===, etc)?

Boolean value (true or false)

*javascript-loops* Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?

Break statement

*Javascript-prototypes* How is it possible to call methods on strings, arrays, and numbers even though those methods don't actually exist on strings, arrays, and numbers?

By prototyping.

*javascript-primitives-and-variables* How do you declare a variable?

By using var keyword, we can declare variables. var(variable keyword) quantity(variable name);

*javascript-this* When is the value of this determined in a function; call time or definition time?

Call time

*javascript-this* What does this refer to in the following code snippet? var character = { firstName: 'Mario', greet: function () { var message = 'It's-a-me, ' + this.firstName + '!'; console.log(message); }};

Character object

*javascript-closures* What allows JavaScript functions to "remember" values from their surroundings?

Closures allow us to remember values from their surrounding.

*javascript-loops* What does "iteration" mean in the context of loops?

Each time that the loop run.

*javascript-view-swapping* At what steps of the solution would it be helpful to log things to the console?

Every step of the way if we are making changes.

*javascript-this* How can you tell what the value of this is for a particular function or method call?

If we know what object is calling it, it's the thing on the left side of the dot. If we cannot see what's calling it function being called, we don't not know. By default, this will be the global window object.

*javascript-closures* What must the return value of myFunction be if the following expression is possible? myFunction()();

In order this code works, we have to return a function.

*javascript-custom-methods* Describe method definition syntax (structure).

Inside the object literal assigned to a variable, list the property, followed by the function key word, then parameters, then curly braces for function definition. const obj = { property: foo(parameter) { } };

*javascript-view-swapping* If you were to add another tab and view to your HTML, but you didn't use event delegation, how would your JavaScript code be written instead?

Instead of putting the addEventlistener on the parent, you would have to add multiple event listeners directly on each element.

*javascript-operators-and-expressions* What does the += "plus-equals" operator do?

It adds the value on the right, to the variable on the left, and then assigns that value back to the variable on the left.

*javascript-forms* What is an advantage of having your console open when writing a JavaScript program?

It allows to log information during the JavaScript development so we can see errors.

*javascript-if* What is the purpose of an if statement?

It allows us to make a decision inside of code.

*Javascript-constructors* What does the new operator do?

It allows you to instantiate. 1. Create a blank, plain JavaScript object. 2. Points newInstance's [[Prototype]] to the constructor function's prototype property, if the prototype is an Object. 3. Executes the constructor function with the given arguments, binding newInstance as the this context. 4. If the constructor function returns a non-primitive, this return value becomes the result of the whole new expression. See the documentation for more info https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/new

*javascript-forms* What does submitting a form without event.preventDefault() do?

It causes the form to refresh the page and to submit the data.

*javascript-functions* What two effects does a return statement have on the behavior of a function?

It causes the function to produce a value.It also exits the function; no code after the return statement is executed.

*javascript-primitives-and-variables* Why is it a good habit to include "labels" when you log values to the browser console?

It gives us much more ease of use on the developer side of things when we're trying to figure out what exactly it is we are looking for especially when we have a collection of console logs.

*javascript-arrays* What is the length property of an array?

It holds the number of items in the array.

*javascript-loops* What does the ++ increment operator do?

It increments (adds one to) its operand and returns the value before or after the increment.

*javascript-objects* What are object properties?

It is a list of variables that we can store data at inside of the object.

*javascript-this* What does it mean to say that this is an "implicit parameter"?

It is available in a function's code block even though it was never included in the function's parameter list or declared with var.

*Javascript-local-storage* When does the 'beforeunload' event fire on the window object?

It is fired before the window, the document and its resources are unloaded.

*javascript-view-swapping* What is the affect of setting an element to display: none?

It makes it invisible and removes it from the document

*javascript-forms* What does the event.preventDefault() method do?

It prevents the browser from automatically reloading the page with the form's values in the URL. In general the event.preventDefault method prevents whatever the default behavior is and in this case when we're working with a form that default behavior is to submit the form back to itself if it doesn't have an action attribute to send the form to then it re-submits to itself and refreshes the page.

*javascript-view-swapping* What does the element.matches() method take as an argument and what does it return?

It takes a CSS selector string as an argument and returns true if an element matches a specific CSS selector(s) and returns false if not(boolean) .

*Javascript-constructors* What does the instanceof operator do?

It tests to see if the prototype property of a constructor appears anywhere in the prototype chain of an object.The return value is a boolean value.

*javascript-functions* What is a function in JavaScript?

It's a collection of code that performs some tasks. The nice thing about functions is that we can give them names so that anytime we need those tasks performed, we can just call the function and it will perform that task.

*javascript-view-swapping* What is the event.target?

It's a reference to the object onto which the event was dispatched.

*javascript-functions* Why are function parameters useful?

It's because they can store data in parameters and then based on the data they can perform whatever it is that they're supposed to do.

*javascript-loops* When does the final expression of a for loop get evaluated?

It's evaluated after the work is completed in a code block and then the final expression is let.

*javascript-loops* When does the condition expression of a for loop get evaluated?

It's evaluated before each loop iteration.

*javascript-loops* When does the condition expression of a while loop get evaluated?

It's evaluated before executing the statement.

*javascript-loops* When does the initialization expression of a for loop get evaluated?

It's evaluated once before the loop begins.

*javascript-closures* What does this code do? const wrap = value => () => value;

It's the same with: const wrap = value => { return () => value }; We have first function that is being defined wrap and then it's going to to be returning another function.

*javascript-this* var character = { firstName: 'Mario', greet: function () { var message = 'It's-a-me, ' + this.firstName + '!'; console.log(message); }}; Given the above character object, what is the result of the following code snippet? Why? character.greet();

It's-a-me, Mario! Because Character is the calling object.

*javascript-this* var character = { firstName: 'Mario', greet: function () { var message = 'It's-a-me, ' + this.firstName + '!'; console.log(message); }}; Given the above character object, what is the result of the following code snippet? Why? var hello = character.greet;hello();

It's-a-me, undefined! Because the calling object is window and it doesn't have a firstName property.

*javascript-and-json* What is JSON?

JavaScript Object Notation (JSON) is a standard text-based format for representing structured data based on JavaScript object syntax. It is commonly used for transmitting data in web applications.

*javascript-if* Describe the syntax (structure) of an if statement.

Keyword "if', condition(operands and the operator between them), opening curly brace, code to execute if the value is true, closing curly brace.

*javascript-primitives-and-variables* What characters are allowed in variable names?

Letter, numbers, dollar sign, underscore. It must not start with a number.

*javascript-methods* What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?

MDN

*javascript-methods* How is a method different from any other function?

Methods are different from other functions because they are attached to objects, unlike normal functions which just kind of floating around out in space.

*javascript-if* Is else required in order to use an if statement?

No

*javascript-methods* Is the return value of a function or method useful in every situation?

No

*javascript-methods* Do string methods change the original string? How would you check if you weren't sure?

No, it does not change the original string. Strings in JavaScript are immutable which means that when we use string methods on them, it does not change the original string. you cannot change strings in JavaScript, you can reassign that variable a new string, you can take parts of a string and create a new string but we cannot change the original string. You can check by using console.log();

*javascript-primitives-and-variables* What is the difference between null and undefined?

Null intentionally empty collection of space whereas undefined would be an open field. Undefined is something where nothing has ever been done, it exists but no value has ever been assigned to it. Null is used as a placeholder value and used to represent that something will be assigned here, it just hasn't been assigned yet.

*javascript-primitives-and-variables* What is the purpose of a number?

Numbers are used to represent numeric values in JavaScript so we can use them for calculation purposes, also we could use them for any numeric value that we need.

*javascript-custom-methods* What is the defining characteristic of Object-Oriented Programming?

Objects can contain both data (as properties) and behavior (as methods).

*Javascript-prototypes* If an object does not have it's own property or method by a given key, where does JavaScript look for it?

Prototype chain

*Javascript-prototypes* What is a prototype in JavaScript?

Prototype is an object that contains properties and (predominantly) methods that you want to prototype onto another object.

*Javascript-constructors* What property of JavaScript functions can store shared behavior for instances created with new?

Prototype property

*javascript-and-json* What are serialization and deserialization?

Serialization is the process of turning an object in memory into a stream of bytes so you can do stuff like store it on disk or send it over the network. (compressing something to a string to be sent) Deserialization is the reverse process: turning a stream of bytes into an object in memory. (unpacking a string into an object that was compressed)

*javascript-primitives-and-variables* Give five examples of JavaScript primitives.

String, number, boolean, null, undefined

*javascript-primitives-and-variables* What is the purpose of a string?

Strings are our way in JavaScript of emulating text or any literal collection of characters.

*javascript-arrays* How do you calculate the last index of an array?

Subtracting 1 from the length of an array.

*javascript-operators-and-expressions* What purpose(s) does the + plus operator serve in JavaScript?

The addition operator ( + ) produces the sum of numeric values or string concatenation.

*javascript-primitives-and-variables* What does it mean to say that variable names are "case sensitive"?

The capitalization should be consistent. So Score and score would be different variable names.

*Javascript-timers* What is the default time delay if you omit the delay parameter from setTimeout() or setInterval()?

The default value is in milliseconds.

*javascript-custom-methods* How is a method different from any other function?

The difference is that a method is associated with an object, while a function is not.

*javascript-functions* Describe the parts of a function definition.

The function keyword, an optional name, a list of parameters within the parentheses(), an opening curly brace, a code block with an optional return statement, and a closing brace.

*javascript-functions* Describe the parts of a function call.

The function name, whatever arguments that the function requires within the parentheses().

*javascript-ajax* What event is fired by XMLHttpRequest objects when they are finished loading the data from the server?

The load event

*javascript-custom-methods* How can you tell the difference between a method definition and a method call?

The method call would indicate when a method on an object is being called and the definition would be part of the definition process as far as when the object is actually being defined.

*Javascript-timers* What do setTimeout() and setInterval() return?

The returned timeoutID is a positive integer value which identifies the timer created by the call to setTimeout(); this value can be passed to clearTimeout() to cancel the timeout. The returned intervalID is a numeric, non-zero value which identifies the timer created by the call to setInterval(); this value can be passed to clearInterval() to cancel the interval.

*javascript-primitives-and-variables* What does the = operator mean in JavaScript?

The single equal operator is the assignment operator and we can use = in order to assign strings or any values.

*javascript-this* What is this in JavaScript?

This is an implicit parameter of all JavaScript functions. The value of this is determined at call time. The value of this can be recognized as "the object to the left of the dot" when the function is called (as a method). It references to the object it is currently in. If not in an object, then it is referencing the window.

*javascript-arrays* What are arrays used for?

To create lists of data.

*javascript-custom-methods* What is the purpose of an API?

To give programmers a way to interact with a system in a simplified, consistent fashion: aka, an abstraction.

*javascript-objects* What are objects used for?

To group together a set of variables and functions.

*javascript-loops* What is the purpose of a condition expression in a loop?

To keep repeating until a specific condition is met.

*javascript-loops* What is the purpose of a loop?

To perform a certain action a number of times until the condition becomes false.

*javascript-methods* Why do we log things to the console?

To print some data and check the console output so we can see what the data is.

*javascript-and-json* How do you deserialize a JSON string into a data structure using JavaScript?

Use JSON.parse() method

*javascript-and-json* How do you serialize a data structure into a JSON string using JavaScript?

Use JSON.stringify() method

*javascript-methods* How do you round a number down to the nearest integer?

Use Math.floor() method

*javascript-methods* How do you generate a random number?

Use Math.random()

*javascript-if* How do you compare two different expressions in the same condition?

Use a logical operator so we could do either a combo expression or sometimes we would use else if so that allows us to check one condition, if that one's not true, we can check another condition.

*javascript-methods* How do you break a string up into an array?

Use a string method split()

*javascript-objects* What are the two ways to get or update the value of a property?

Use dot notation or bracket notation.

*javascript-loops* How do you iterate through the keys of an object?

Use for ... in loop.

*javascript-view-swapping* How can you retrieve the value of an element's attribute?

Use getAttribute() method.

*javascript-methods* How do you remove the last element from an array?

Use pop() method

*Javascript-timers* How can you set up a function to be called repeatedly without using a loop?

Use setInterval() function

*Javascript-timers* Besides adding an event listener callback function to an element or the document, what is one way to delay the execution of a JavaScript function until some point in the future?

Use setTimeout() function

*Javascript-local-storage* How to you retrieve data from localStorage?

Use the getItem() method localStorage.getItem(key)

*javascript-objects* How do you remove a property from an object?

Use the keyword delete, and then use dot notation to identify the property or method you want to remove from the object.

*Javascript-local-storage* How to you store data in localStorage?

Use the setItem() method localStorage.setItem(key,value)

*javascript-arrays* Describe array literal notation.

Variable keyword and variable name and = operator and an opening square bracket and a series of comma delineated values and a closing square bracket.

*javascript-primitives-and-variables* What is the purpose of variables?

Variables are used to store data that we can access later.

*javascript-forms* What is one risk of writing a lot of code without checking to see if it works so far?

We can lose where we got wrong. Make sure each line is working without guessing!

*javascript-primitives-and-variables* How do you update the value of a variable?

We don't need to use the bar keyword, we just use the anime of the variable and the assignment operator and the new value.

*javascript-primitives-and-variables* How do you initialize (assign a value to) a variable?

We would have a variable name and assignment operator (=) and the value we want to assign.

*javascript-closures* In JavaScript, when is a function's scope determined; when it is called or when it is defined?

When it is defined. The functions when we define them, that's where their scope is determined and that's their lexical scope.

*javascript-functions* When comparing them side-by-side, what are the differences between a function call and a function definition?

When we define it, we have to use a keyword, we have to give it an optional name or not, a parameter list and have the curly braces and all the statements of the code that we want to execute. When we call the function, we just need to use the name of the function and whatever arguments are required for that function.

*javascript-ajax* Which object is built into the browser for making HTTP requests in JavaScript?

XMLHttpRequests

*javascript-this* How can you tell what the value of this will be for a particular function or method definition?

You don't know till it is called

*javascript-view-swapping* If you didn't use a loop to conditionally show or hide the views in the page, how would your JavaScript code be written instead?

You would have to use else if statement instead of a loop.

*javascript-forms* What event is fired when a user's cursor leaves a form control?

blur

*javascript-forms* What property of a form element object contains all of the form's controls.

elements

*javascript-forms* What event is fired when a user places their cursor in a form control?

focus

*javascript-forms* What event is fired as a user changes the value of a form control?

input

*javascript-custom-methods* Describe method call syntax (structure).

object.property(argument)

*Javascript-prototypes* What kind of inheritance does the JavaScript programming language use?

prototypal inheritance

*javascript-ajax* Bonus Question: An XMLHttpRequest object has an addEventListener() method just like DOM elements. How is it possible that they both share this functionality?

prototypal inheritance, They have a shared prototype object.

*javascript-methods* How do you append an element to an array?

push() - add an item to the end of an array unshift() - add it to the front of an array

*javascript-methods* How do you delete an element from an array?

shift() - remove from the front pop() - remove from the rear splice() - remove from wherever you tell it to

*Javascript-local-storage* What data type can localStorage save in the browser?

strings

*javascript-forms* What event is fired when a user clicks the "submit" button within a ?

submit

*javascript-forms* What property of form a control object gets and sets its value?

value


Kaugnay na mga set ng pag-aaral

Domain 5: Principles of Economics

View Set

CCNA Part 2 Questions 250 and up

View Set

MCB 5252 - Exam 3 Study Guide (EU)

View Set

Chapter 14, 17, and 18: history vocab

View Set

Populism and Segregation (Test Answers)

View Set

Ch. 13 - Labor and Birth Processes

View Set

"Psychiatric/Mental Health Nursing - Psychobiological Disorders + Foundations"

View Set

Quiz 16 Corporate strategy - Mergers and acquisitions STRAT MAN

View Set