Questions and Answers
- Which operator returns true if the two compared values are not equal?
- `<>`
- `~`
- `==!`
- `!==`
- How is a forEach statement different from a for statement?
- Only a for statement uses a callback function.
- A for statement is generic, but a forEach statement can be used only with an array.
- Only a forEach statement lets you specify your own iterator.
- A forEach statement is generic, but a for statement can be used only with an array.
- Review the code below. Which statement calls the addTax function and passes 50 as an argument? How would you use this function to find out how much tax should be paid on \$50?
- `addTax = 50;`
- `return addTax 50;`
- `addTax(50);`
- `addTax 50;`
- Which statement is the correct way to create a variable called rate and assign it the value 100?
- `let rate = 100;`
- `let 100 = rate;`
- `100 = let rate;`
- `rate = 100;`
- Which statement creates a new object using the Person constructor? Which statement creates a new Person object called "student"?
- `var student = new Person();`
- `var student = construct Person;`
- `var student = Person();`
- `var student = construct Person();`
- When would the final statement in the code shown be logged to the console? When would 'results shown' be logged to the console?
- after 10 second
- after results are received from the HTTP request
- after 10000 seconds
- immediately
- Which snippet could you add to this code to print "food" to the console?
- `a.prototype.belly[0]`
- `Object.getPrototype0f (a).belly[0]`
- `Animal.belly[0]`
- `a.belly[0]`
- How does a function create a closure?
- It reloads the document whenever the value changes.
- It returns a reference to a variable in its parent scope.
- It completes execution without returning.
- It copies a local variable to the global scope.
- Which statement creates a new function called discountPrice?
- [x]
- [ ]
- [ ]
- [ ]
- What is the result in the console of running the code shown?
- Storm()
- undefined
- 'rain'
- 'snow'
- What is the result in the console of running this code?
- `undefined`
- `window`
- `{desc: "logger"}`
- `function`
- How would you reference the text 'avenue' in the code shown?
- roadTypes.2
- roadTypes\[3\]
- roadTypes.3
- roadTypes\[2\]
- What is the result of running this statement?
- `'float'`
- `'value'`
- `'number'`
- `'integer'`
- Which property references the DOM object that dispatched an event?
- `self`
- `object`
- `target`
- `source`
- You're adding error handling to the code shown. Which code would you include within the if statement to specify an error message?
- `exception('One or both parameters are not numbers')`
- `catch('One or both parameters are not numbers')`
- `error('One or both parameters are not numbers')`
- `throw('One or both parameters are not numbers')`
- Which method converts JSON data to a JavaScript object?
- `JSON.fromString();`
- `JSON.parse()`
- `JSON.toObject()`
- `JSON.stringify()`
- When would you use a conditional statement?
- When you want to reuse a set of statements multiple times.
- When you want your code to choose between multiple options.
- When you want to group data together.
- When you want to loop through a group of statement.
- What would be the result in the console of running this code?
- 12345
- 1234
- 01234
- 012345
- Which Object method returns an iterable that can be used to iterate over the properties of an object?
- `Object.get()`
- `Object.loop()`
- `Object.each()`
- `Object.keys()`
- What will be logged to the console?
- 101
- 3
- 4
- 100
- What is one difference between collections created with Map and collections created with Object?
- You can iterate over values in a Map in their insertion order.
- You can count the records in a Map with a single method call.
- Keys in Maps can be strings.
- You can access values in a Map without iterating over the whole collection.
- What is the value of dessert.type after executing this code?
- pie
- The code will throw an error.
- pudding
- undefined
- 0 && hi
- ReferenceError
- True
- 0
- false
- Which of the following operators can be used to do a short-circuit evaluation?
- `\++`
- `\--`
- `\==`
- `\|\|`
- Which statement sets the Person constructor as the parent of the Student constructor in the prototype chain?
- `Student.parent = Person;`
- `Student.prototype = new Person();`
- `Student.prototype = Person;`
- `Student.prototype = Person();`
- Why would you include a "use strict" statement in a JavaScript file?
- to tell parsers to interpret your JavaScript syntax loosely
- to tell parsers to enforce all JavaScript syntax rules when processing your code
- to instruct the browser to automatically fix any errors it finds in the code
- to enable ES6 features in your code
- Which Variable-defining keyword allows its variable to be accessed (as undefined) before the line that defines it?
- all of them
- `const`
- `var`
- `let`
- Which of the following values is not a Boolean false?
- `Boolean(0)`
- `Boolean("")`
- `Boolean(NaN)`
- `Boolean("false")`
- Which of the following is not a keyword in JavaScript?
- `this`
- `catch`
- `function`
- `array`
- Which variable is an implicit parameter for every function in JavaScript?
- Arguments
- args
- argsArray
- argumentsList
- For the following class, how do you get the value of 42 from an instance of X?
- `x.get('Y')`
- `x.Y`
- `x.Y()`
- `x.get().Y`
- What is the result of running this code?
- 30, ReferenceError, 30, -10
- 30, ReferenceError
- 30, -10
- ReferenceError, -10
- Why is it usually better to work with Objects instead of Arrays to store a collection of records?
- Objects are more efficient in terms of storage.
- Adding a record to an object is significantly faster than pushing a record into an array.
- Most operations involve looking up a record, and objects can do that better than arrays.
- Working with objects makes the code more readable.
- Which statement is true about the "async" attribute for the HTML script tag?
- It can be used for both internal and external JavaScript code.
- It can be used only for internal JavaScript code.
- It can be used only for internal or external JavaScript code that exports a promise.
- It can be used only for external JavaScript code.
- How do you import the lodash library making it top-level Api available as the "\_" variable?
- `import _ from 'lodash';`
- `import 'lodash' as _;`
- `import '_' from 'lodash;`
- `import lodash as _ from 'lodash';`
- What does the following expression evaluate to?
- True
- undefined
- []
- False
- What type of function can have its execution suspended and then resumed at a later point?
- Generator function
- Arrow function
- Async/ Await function
- Promise function
- What will this code print?
- 2
- 1
- Nothing - this code will throw an error.
- undefined
- Which statement is true about Functional Programming?
- Every object in the program has to be a function.
- Code is grouped with the state it modifies.
- Date fields and methods are kept in units.
- Side effects are not allowed.
- Your code is producing the error: TypeError: Cannot read property 'reduce' of undefined. What does that mean?
- You are calling a method named reduce on an object that's declared but has no value.
- You are calling a method named reduce on an object that does not exist.
- You are calling a method named reduce on an empty array.
- You are calling a method named reduce on an object that's has a null value.
- How many prototype objects are in the chain for the following array?
- 3
- 2
- 0
- 1
- Which choice is _not_ a unary operator?
- `typeof`
- `delete`
- `instanceof`
- `void`
- What type of scope does the end variable have in the code shown?
- conditional
- block
- global
- function
- What will the value of y be in this code:
- One
- undefined
- TRUE
- Two
- Which keyword is used to create an error?
- `throw`
- `exception`
- `catch`
- `error`
- What's one difference between the async and defer attributes of the HTML script tag?
- The defer attribute can work synchronously.
- The defer attribute works only with generators.
- The defer attribute works only with promises.
- The defer attribute will asynchronously load the scripts in order.
- The following program has a problem. What is it?
- The condition in the ternary is using the assignment operator.
- You can't define a variable without initializing it.
- You can't use a ternary in the right-hand side of an assignment operator.
- The code is using the deprecated var keyword.
- Which statement references the DOM node created by the code shown?
- `Document.querySelector('class.pull')`
- `document.querySelector('.pull');`
- `Document.querySelector('pull')`
- `Document.querySelector('#pull')`
- What value does this code return?
- 10
- true
- false
- 0
- What is the result in the console of running the code shown?
- 10
- 0
- ReferenceError
- undefined
- What will this code log in the console?
- undefined
- "hello"
- an object with a constructor property
- an error message
- Which collection object allows unique value to be inserted only once?
- Object
- Set
- Array
- Map
- What two values will this code print?
- `1` then `1`
- `1` then `undefined`
- `undefined` then `undefined`
- `undefined` then `1`
- How does the `forEach()` method differ from a `for` statement?
- forEach allows you to specify your own iterator, whereas for does not.
- forEach can be used only with strings, whereas for can be used with additional data types.
- forEach can be used only with an array, whereas for can be used with additional data types.
- for loops can be nested; whereas forEach loops cannot.
- Which choice is an incorrect way to define an arrow function that returns an empty object?
- => `({})`
- => `{}`
- => `{ return {};}`
- => `(({}))`
- Why might you choose to make your code asynchronous?
- to start tasks that might take some time without blocking subsequent tasks from executing immediately
- to ensure that tasks further down in your code are not initiated until earlier tasks have completed
- to make your code faster
- to ensure that the call stack maintains a LIFO (Last in, First Out) structure
- Which expression evaluates to true?
- `[3] == [3]`
- `3 == '3'`
- `3 != '3'`
- `3 === '3'`
- Which of these is a valid variable name?
- 5thItem
- firstName
- grand total
- function
- Which method cancels event default behavior?
- `cancel()`
- `stop()`
- `preventDefault()`
- `prevent()`
- Which method do you use to attach one DOM node to another?
- `attachNode()`
- `getNode()`
- `querySelector()`
- `appendChild()`
- Which statement is used to skip iteration of the loop?
- `break`
- `pass`
- `skip`
- `continue`
- Which choice is valid example for an arrow function?
- `(a,b) => c`
- `a, b => {return c;}`
- `a, b => c`
- `{ a, b } => c`
- Which concept is defined as a template that can be used to generate different objects that share some shape and/or behavior?
- class
- generator function
- map
- proxy
- How do you add a comment to JavaScript code?
- `! This is a comment`
- `# This is a comment`
- `\\ This is a comment`
- `// This is a comment`
- If you attempt to call a value as a function but the value is not a function, what kind of error would you get?
- TypeError
- SystemError
- SyntaxError
- LogicError
- Which method is called automatically when an object is initialized?
- create()
- new()
- constructor()
- init()
- What is the result of running the statement shown?
- 4
- 10
- 6
- 5
- You've written the event listener shown below for a form button, but each time you click the button, the page reloads. Which statement would stop this from happening?
- `e.blockReload();`
- `button.preventDefault();`
- `button.blockReload();`
- `e.preventDefault();`
- Which statement represents the starting code converted to an IIFE?
- `function() { console.log('lorem ipsum'); }()();`
- `function() { console.log('lorem ipsum'); }();`
- `(function() { console.log('lorem ipsum'); })();`
- Which statement selects all img elements in the DOM tree?
- `Document.querySelector('img')`
- `Document.querySelectorAll('')`
- `Document.querySelectorAll('img')`
- `Document.querySelector('')`
- Why would you choose an asynchronous structure for your code?
- To use ES6 syntax
- To start tasks that might take some time without blocking subsequent tasks from executing immediately
- To ensure that parsers enforce all JavaScript syntax rules when processing your code
- To ensure that tasks further down in your code aren't initiated until earlier tasks have completed
- What is the HTTP verb to request the contents of an existing resource?
- DELETE
- GET
- PATCH
- POST
- Which event is fired on a text field within a form when a user tabs to it, or clicks or touches it?
- focus
- blur
- hover
- enter
- What is the result in the console of running this code?
- function
- undefined
- Function.prototype
- window
- Which class-based component is equivalent to this function component?
- `class Greeting extends React.Component { render() { return
Hello {this.props.name}!
; } }` - `class Greeting extends React.Component { constructor() { return
Hello {this.props.name}!
; } }` - `class Greeting extends React.Component {
Hello {this.props.name}! ; } }` - `class Greeting extends React.Component { render({ name }) { return
Hello {name}!
; } }`
- `class Greeting extends React.Component { render() { return
- Which class-based lifecycle method would be called at the same time as this effect Hook?
- componentWillUnmount
- componentDidUpdate
- render
- componentDidMount
- What is the output of this code?
- `ReferenceError: obj is not defined`
- `{}`
- `undefined`
- `null`
- How would you use the TaxCalculator to determine the amount of tax on \$50?
- calculate(50);
- new TaxCalculator().calculate(\$50);
- TaxCalculator.calculate(50);
- new TaxCalculator().calculate(50);
- What will be logged to the console?
- [ ]
- [ ]
- The output may change with each execution of code and cannot be determined.
- [ ]
- What will this code log to the console?
- 1
- undefined
- NaN
- Nothing--this is not proper JavaScript syntax and will throw an error.
- How do you remove the property name from this object?
- delete name from foo;
- delete foo.name;
- del foo.name;
- remove foo.name;
- Which concept does this code illustrate?
- overloading
- closure
- currying
- overriding
- Which tag pair is used in HTML to embed JavaScript?
- ``
- `
` - `
` - `
`
- What is the value of `dessert.type` after executing this code?
- pie
- fruit
- undefined
- pudding
- If your app receives data from a third-party API, which HTTP response header must the server specify to allow exceptions to the same-origin policy?
- Security-Mode
- Access-Control-Allow-Origin
- Different-Origin
- Same-Origin
- What will be logged to the console??
- window
- undefined
- function
- {desc: "logger"}
- Which statement is applicable to the defer attribute of the HTML \
Copyright © 2024 All Rights Reserved.