JS1 - Ethan

¡Supera tus tareas y exámenes ahora con Quizwiz!

Arrow functions ___ suitable for ___, ___, and ___ ___, which generally rely on establishing a ___.

are NOT; call; apply; bind; methods; scope

How to combine [[1, 2], [3, 4, 5]] and [1, 2, 3, 4, 5] using Array.concat() and Array.apply()?

arr1.concat(arr2); Array.apply(null, arr1, arr2);

An ___ is NOT the same as a ___.

array; tuple

Given the Animal constructor, which method creates a new instance of the object? function Animal (size, age) { this.size = size; this.age = age; this.canTalk = false; } (a) Object.create('Animal'); (b) new Animal('large', 10); (c) Object.prototype(Animal); (d) Object.new(Animal);

(b) new Animal('large', 10);

Why would a developer specify a package in the package.json as a peerDependency? (a) It is required by the application in production. (b) It is only needed for local development and testing. (c) Other required packages depend on it. (d) It should be bundled with other packages when the package is published.

(c) Other required packages depend on it. Determine the version of the host package you peer-depend on for all environments, and add it to your package.json.

A developer wants to use a module called DatePrettyPrint. This module exports one default function called printDate(). How can a developer import and use the printDate() function? (a) import printDate() from '/path/DatePrettyPrint.js'; printDate(); (b) import printDate from '/path/DatePrettyPrint.js'; printDate(); (c) import DatePrettyPrint from '/path/DatePrettyPrint.js'; DatePrettyPrint.printDate(); (d) import printDate from '/path/DatePrettyPrint.js'; DatePrettyPrint.printDate();

(b) import printDate from '/path/DatePrettyPrint.js'; printDate();

The purpose of ___ is to indicate that the code should be executed in ___. With ___, you cannot, for example, use ___.

"use strict"; "strict mode"; strict mode; undeclared variables

NaN.toString = ?

'NaN'

What are the different data types used in JavaScript?

(1) string (2) number (3) BigInt (4) Boolean (5) null (6) undefined (7) object (8) symbol

For this code, which of the following code lines will assert that the sumArr method adds the numbers in the array passed in? let res = sumArr([2, 3, 4]); (a) console.assert(res === 9); (b) console.log(res === 9); (c) console.assert(res != 9); (d) console.error(res != 9);

(a) console.assert(res === 9); The console.assert method writes an error message to the console if the assertion is false. If the assertion is true, nothing happens.

Which two syntax examples correctly initialize a value to the variable strLang? (a) let strLang = 'javascript'; (b) const strLang = 'java' + 'script'; (c) let strLang = javascript; (d) str strLang = 'javascript';

(a) let strLang = 'javascript'; (b) const strLang = 'java' + 'script'

Referring to the code, which two answers correctly execute p1 and p2? (a) p1.then((data) => p2(data)).then(result => result); (b) async function getResult() { const data = await p1; return await p2(data); } getResult(); (c) p1().then(function() { p2().then(function(result) { return result; }); }); (d) async function getResult() { const data = p1; const result = p2(data); } await getResult();

(a) p1.then((data) => p2(data)).then(result => result); ^The method promise.then() is used to associate further action with a promise that becomes settled. (b) async function getResult() { const data = await p1; return await p2(data); } getResult(); ^Using await inside the function causes both to execute.

If an application manipulates the browser history using the History API, which event should a developer use to detect when the browser's native back or forward button is clicked? (a) popstate (b) navigate (c) pushstate (d) change

(a) popstate A popstate event is dispatched to the window each time the active history entry changes between two history entries for the same document.

Which code does the developer need to add to line 03 to receive incoming request data? (a) req.on('data', (chunk) => { (b) req.get((chunk) => { (c) req.data((chunk) => { (d) req.on('get', (chunk) => {

(a) req.on('data', (chunk) => { The CHUNK argument is passed in for JSON.parse to use.

Which statement sorts this number array so it is in ASCENDING order? const arr = [7, 3, 400, 10]; (a) arr.sort(); (b) arr.sort((a, b) => a - b); (c) arr.sort((a, b) => a < b); (d) arr.sort((a, b) => b - a);

(b) arr.sort((a, b) => a - b); Ascending means 'a' is first :)

A developer wants to set a breakpoint in his code while in the editor so they don't have to switch to the browser. What is the in-line command for setting a breakpoint? (a) break (b) debugger (c) debug (d) breakpoint

(b) debugger

Given the code on the right, the sum3 method gets updated to multiply the numbers instead of adding them. Line 02 is now a false-positive assertion. How can the test be changed to fix this? let res = sum3([1, 2, 3]); console.assert(res === 6); (c) let res = sum3([1, 2, 3, 4]); console.assert(res === 24);

(c) let res = sum3([1, 2, 3, 4]); console.assert(res === 24); Adding another number in the sequence ensures the result is different if added or multiplied.

What are the two main properties of an error object that's passed as an argument to catch in a try...catch construct? (a) name and stacktrace (b) title and mesage (c) title and stack (d) name and message

(d) NAME and MESSAGE

Given two nested divs and the following code, in what order will the event listeners be called when the innerDiv is clicked? .addEventListener('click', displayOuterMessage,true); .addEventListener('click', displayInnerMessage,false); (a) displayInnerMessage, displayOuterMessage (b) displayInnerMessage (c) displayOuterMessage (d) displayOuterMessage, displayInnerMessage

(d) displayOuterMessage, displayInnerMessage Event capturing is set to true, calling the events in order from outside to inside.

Events are fired inside the browser window and tend to attach to specific items residing in the browser. What are some of these items?

- a single element - a set of elements - the HTML document loaded in the current tab - the entire browser window

What are some of the basic DOM data types?

- document - node - element - nodeList - attribute - namedNodemap

variable VAR: • Either ___ or ___ scoped. • Do NOT support ___. • This means that if a variable is defined in a ___ or in an ___, it ___ be accessed ___ the ___ and accidentally ___, leading to a buggy program. • As a general rule, ___.

- globally-; functionally-; - block-level scope; - loop; if statement; CAN; outside; block; redefined; - avoid using

variable LET: • Similar to the ___ keyword, as they both allow you to ___ the value later on. • The main difference between the two is that ___ deals with a ___ and although it can be ___, it CANNOT be ___.

- var; reassign; - let; block scope; reassigned; redeclared

Float: ___ bit (___ digits) Double: ___ bit (___ digits) Decimal: ___ bit (___ significant digits)

32 bit; 7 digits; 64 bit; 15-16 digits; 128 bit; 28-29 significant digits

What is the proper syntax for adding placeholders in template literals?

A dollar sign followed by curly braces: ${expression}

Array with multiple types inside? (i.e. ['string', 1, {}, null]

Allowed

___ don't have their own ___ to ___, ___, or ___, and should NOT be used as ___.

Arrow functions; bindings; this; arguments, super; methods

Arrow functions ___ be used as ___.

CANNOT; constructors

Arrow functions ___ use ___ within its ___.

CANNOT; yield; body

Arrow functions ___ have access to the ___.

DON'T; new.target keyword

Which npm? - "Fast, unopinionated, minimalist web FRAMEWORK for node." - Great for simple server + navigation, HTTP, HTTPS. - Middleware: includes routing and templates in the application framework

Express

The ___ provides information about ___ and allows ___ in a ___ to access their ___.

File interface; files; JavaScript; web page; content

A ___ is a specific kind of ___ and can be used in any context that a ___ can. In particular, the following accept both ___ and ___: - FileReader - URL.createObject(URL() - createImageBitmap() - XMLHttpRequest.send()

File object; Blob; Blob; Blobs; Files

___ are generally retrieved from a ___ returned as a result of a user selecting ___ using the ___, or from a ___ operation's ___.

File objects; FileList object; files; <input> element; drag and drop; DataTransfer object

I believe the correct answer would be ___. ___ is the ___.

FileReader.readAsDataURL(); File(); parent object

What type is this? 3.1415926?

Float

___ is legitimate and can be used for a ___. ___ can be used for any ___ but is not ___ like ___.

HTTPS; secure server; HTTP; server; secure; HTTPS

DOM events--think of which ones can be used to help notify when a page has fully loaded

Handle this by: (1) checking onLoad (2) adding an eventListener for load

What are some benefits of using breakpoints?

JavaScript will stop executing at each breakpoint to let you examine the current JavaScript values. After examining the values, you can resume the execution of code. You can even step from breakpoint to breakpoint.

Where can you use the await keyword and what does it do?

Keyword await works only INSIDE async functions and makes JavaScript wait until that promise settles and returns its result

Which npm? - Expressive HTTP middleware FRAMEWORK for node.js to make web applications and APIs more enjoyable to work with. - Its middleware stack flows in a stack-like manner, allowing you to perform actions downstream, then filter and manipulate the response upstrea. - Only methods that are common to nearly all HTTP servers are integrated directly into its small ~570 SLOC codebase. This in includes things like content negotiation, normalization of node inconsistencies, redirect, and a few others. - Middleware: requires modules, making it more modular or customizable

Koa

Which collections of data are ordered by a key?

Map objects Set objects

Does .then have to come before .catch?

No, but if .catch is hit first, then the .then after will be called and be undefined. The .then runs on an if(data) context when called first, but not after.

What type of instance is null?

Object

The ___ method prevents new ___ from ever being added to an ___ (i.e. prevents future ___ to the ___). It also prevents the ___ from being ___.

Object.preventExtensions(); properties; object; extensions; object; object's prototype; reassigned

When it comes to frameworks, what is one of the main benefits of using popular frameworks?

One of the main benefits is a strong community supporting the framework. This usually results in good documentation and resources.

Which npm? - JavaScript LIBRARY - Focuses on creating reusable UI components - Rendering content to DOM: uses JSX (a ___ extension to JavaScript)

React

For example: let val = new Promise((resolve, reject) => { resolve('data') }); val.then(data => { console.log(data) }).catch(err => { console.log(err); }).then(data => { console.log(data); }) What happens if resolves? What happens if rejects?

Resolve: {'data', undefined} Reject: {'error', undefined}

Start of Study for the Salesforce JavaScript Developer I Exam trail

Start of Study for the Salesforce JavaScript Developer I Exam trail

What code block can be executed regardless of whether an exception was thrown or caught in a try...catch block?

The finally block can be used to execute code at the end of a try...catch block. It will run even if no catch block handles the exception.

What is the correct code to replace the last line with an async/await function? getId.then(bId => getBook(bId)).then(data => data); (a) async function getBookInfo() { const bId = await getId; const result = await getBook(bId); } getBookInfo();

The await function is always inside an async function.

What are the most important items in your npm package.json file if you plan to publish a package?

The name and version. Together, they form a unique identifier for the package.

A developer wrote a method and created some test assertions for it. Now another developer has updated the method and the tests are still passing. Should the tests be updated?

The test should be verified for possible false positives. New tests should be added to assert the way the method was updated.

A developer is not able to use a variable outside a function that is defined inside a function. What could be causing this?

Variables defined inside a function cannot be accessed from anywhere outside the function, because the variable is defined only in the scope of the function.

Which npm? - JavaScript FRAMEWORK - Provides developers with front-end tools - Rendering content to DOM: uses HTML templates

Vue

Using ___ + ___ in ___.

Yarn + package dependencies; shared workspaces; Workspaces are a new way to set up your package architecture. It allows you to set up multiple packages in such a way that you only need to run `yarn install` once to install all of them in a single pass. Your dependencies can be linked together, which means that your workspaces can depend on one another. All your project dependencies will be installed together. Yarn will use a single lockfile rather than a different one for each project.

___ is a ___ that doubles as a ___.

Yarn; package manager; project manager

If black-box testing treats software under test as a black-box without knowing its internals, what is white-block testing?

White-box testing is aware of the internal code being tested and uses it as part of the testing.

When using the const identifier to create an instance of an object, are the properties changeable?

YES. An object declared as const CAN be modified. The const fixes the VALUE of the object but not its contents.

function sayHello(name) { return 'Hello ' + name; } const world = function() { return 'World'; } console.log(sayHello(world)); If do console.log(sayHello(world));, what is returned? How to get it to say 'Hello World'?

a function instead of a result is returned; sayHello(world());

setTimeout(func(), 0) An ___ method, even with an ___. Will be added to the ___ after any ___ and will almost always run AFTER (___).

asynchronous; immediate timeout; call stack; synchronous code; (single threaded)

A ___ variable means that the variable defined within a ___ will ___ be accessible from outside the ___. A ___ can reside inside a ___, and a ___ variable will ___ be available outside the ___, even if the ___ is inside a ___.

block-scoped; block; NOT; block; block; function; block-scoped; NOT; block; block; function

You can modify the ___ from the ___.

browser UI; browser console

You can control the ___ via ___.

browser; console CLI

Lightning Web Components are ___ built using ___ and ___.

custom HTML elements; standard HTML; modern JavaScript

The Tuple type represents a JavaScript array where you can ___ the ___ of each ___ in the ___. A tuple is a ___ of array that stores ___ belonging to the different ___ into the same collection.

define; data type; element; array; special type; multiple fields; data types

How to ensure an ___ fires ___?

event; only one time; target.removeEventListener(); element.addEventListener(event, func, {once: true});

Similarly, you can ___ using the browser console. But while the ___ executes code in the ___ scope, the ___ executes them in the scope of the ___. This means you can interact with ___ using the ___, and even with the ___ used to specify the browser's ___.

execute JavaScript expressions; Web Console; page window scope; Browser Console; browser's chrome window; all the browser's tabs; gBrowser global; XUL; user interface

A ___ variable means that the variable defined within a ___ will ___ be accessible from outside the ___.

function-scoped; function; NOT; function

The browser console logs ___ for all ___, for ___, and for the browser's ___.

information; content tabs; add-ons; own code

Arrays can have varying ___ and ___ with no issue. If you want to restrict this, define a ___. Handling for data in an array with multiple ___ can be extremely taxing and it's ___ to store data this way.

lengths; contents; typed array; types; NOT recommended

// Traditional function function bob(a) { return a + 100; } // Arrow function const bob2 = (a) => a + 100;

n/a

example: window.addEventListener('load', function() { alert("It's loaded!"); })

n/a

For ___ functions, we treat ___ like ___.

named; arrow expressions; variables

___'s Express, Joa, Vue, React

npm

Basic syntax for arrow function ___ => ___ (___) => ___

param; expression param; expression

setInterval vs setTimeout?

setInterval fires repeatedly at the set interval. setTimeout runs only once.

Floats handle up to ___ and allow ___. Double is ___. Decimal is most ___ with no ___.

seven digits; rounding errors; moderate; accurate; rounding errors

The promise object returned by the new Promise constructor has internal properties. What are they?

state - initially "pending", then changes to either "fulfilled" when resolve is called or "rejected" when reject is called result - initially undefined, then changes to value when resolve(value) called or error when reject(error) is called

If you are used to using npm, you might expecting to use --save or --save-dev. These have been replaced by ___ and ___.

yarn add; yarn add --dev


Conjuntos de estudio relacionados

Anatomy Ch 24 the respiratory system

View Set

Chapter 16-18 Honors U.S. History WHS

View Set

Lesson 6: Language Focus: Expressing Ideas Concisely - Practice (Unit 1) (1/2)

View Set

FIN 4010 Exam 2 - Conceptual Questions

View Set

Cardiac conduction and rhythm prepU

View Set