Javascript Dev 1 Cert Flashcards
The name of a variable is called ___
Identifier
____ can be used to declare a local or global variable and can be initialed to a value
var
____ can be used to declare a block-scoped, local variable and can be initialized
let
___ can be used to declare a block-scoped, read-only constant. It must be initialized to a value.
const
What is the value of var1?
let var1;
undefined
What is the value of var1?
var var1;
undefined
What data type is this?
let var1 = 123444555666777n;
BigInt
What is the output?
let field1 = Symbol('field'); let field2 = Symbol('field'); console.log(field1 === field2); console.log(Symbol('field') == Symbol('field'));
false
false
What is the output?
let record = {}; record = null; console.log(typeof record);
object
What is the output?
let var1 = undefined; let var2 = null; console.log(var1 == var2);
true
What is the output?
let var1 = NaN; let var2 = NaN; console.log(var1 == var2); console.log(var1 === var2);
false
false
nothing is ever equal to NaN
What is the output?
let var1 = -0; let var2 = 0; console.log(var1 == var2); console.log(var1 === var2);
true
true
What is the output?
const bool = true; const str = '5'; console.log(str == 5);
true
trick question! don’t let this mess you up
What is the output?
const bool = true; console.log(bool == 5);
false
What is the output?
const bool = true; console.log(+bool); console.log(typeof +bool);
1 Number
What is the output?
const str = '5'; console.log(+str); console.log(typeof +str);
5 Number
What is the output?
const bool = true; const str = '5'; console.log(bool & str); console.log(bool && str);
1
5
What is the output?
const bool = true; const str = '5'; console.log(bool == str); console.log(bool === str);
false
false
What is the output?
let name; console.log(typeof name);
undefined
What is the output?
console.log(Array.from('123'));
[“1”, “2”, “3”]
What is the output?
Array.of('jan', 'feb', 'mar');
[“jan”, “feb”, “mar”]
What character is used to define a template literal string?
Backtick character (`)
When a date object is created, what does it actually contain?
A number representing the number of milliseconds since 00:00:00 UTC on January 1st, 1970.
What are two ways to create a number?
A number literal and the Number constructor.
What does the bigint data type allow?
Storing and operating on big numbers
Which keyword should be used to define a value that should not change in the application?
const
What type of coercion is automatically performed?
Implicit coercion
If the value of ‘data’ is a string, which data type will it be coerced to when data == 0 is used to check its value?
Number
To explicitly convert a boolean, what function is used?
Boolean()
___ can be used to check whether a given value evaluates to true or false
!! (double bang)
___ can be used to check whether a given expression evaluates to true and execute code accordingly.
Conditional (ternary) operator
The ___ operator performs type conversion before comparing two values
loose equality operator (==)
The ___ operator compares both type and value
strict equality operator (===)
what is the output?
{} == {a: 1, b:2}
false
what is the output?
[] == [1, 2]
false
what is the output?
[1] == [1]
false
what is the output?
[1] === [1]
false
what is the output?
{} == {}
false
what is the output?
{} === {}
false
truthy or falsey
‘0’ //(string containing 0)
truthy
truthy or falsey
‘false’ (string containing false)
truthy
truthy or falsey
47 (a number other than 0 and -0)
truthy
truthy or falsey
Infinity
truthy
truthy or falsey
-Infinity
truthy
truthy or falsey
0 (the number 0)
falsey
truthy or falsey
-0 (the number negative 0)
falsey
truthy or falsey
0n (BigInt 0)
falsey
truthy or falsey
‘’ (empty string)
falsey
truthy or falsey
null
falsey
truthy or falsey
undefined
falsey
truthy or falsey
NaN (not a number)
falsey
What is the output?
const array1 = [1, 2, 3, 4]; const initialValue = 1; const sumWithInitial = array1.reduce( (accumulator, currentValue) => accumulator + currentValue, initialValue ); console.log(sumWithInitial);
11
What is the output?
const colors = ['Blue', 'Green', 'Yelow', 'Purple']; console.log(colors); months.splice(1, 0, 'Red'); console.log(colors); colors.splice(4, 1, 'Orange'); console.log(colors);
[‘Blue’, ‘Green’, ‘Yelow’, ‘Purple’]
[‘Blue’, ‘Red’, ‘Green’, ‘Yelow’, ‘Purple’]
[‘Blue’, ‘Red’, ‘Green’, ‘Yelow’, ‘Orange’]
What is the output?
const array1 = [1, 2, 3]; console.log(array1.unshift(4, 5)); console.log(array1);
Array [4, 5, 1, 2, 3]
What is the output?
const plants = ['broccoli', 'cauliflower', 'cabbage', 'kale', 'tomato']; console.log(plants.pop()); console.log(plants); plants.pop(); console.log(plants);
“tomato”
Array [“broccoli”, “cauliflower”, “cabbage”, “kale”]
plants.pop();
Array [“broccoli”, “cauliflower”, “cabbage”]
What is the output?
const plants = ['broccoli', 'cauliflower', 'cabbage', 'kale', 'tomato']; console.log(plants.pop()); console.log(plants); plants.pop(); console.log(plants);
“tomato”
Array [“broccoli”, “cauliflower”, “cabbage”, “kale”]
plants.pop();
Array [“broccoli”, “cauliflower”, “cabbage”]
What is the output?
const animals = ['ant', 'bison', 'camel', 'duck', 'elephant']; console.log(animals.slice(2)); console.log(animals.slice(2, 4)); console.log(animals.slice(1, 5)); console.log(animals.slice(-2)); console.log(animals.slice(2, -1)); console.log(animals.slice());
[‘camel’, ‘duck’, ‘elephant’]
[‘camel’, ‘duck’]
[‘bison’, ‘camel’, ‘duck’, ‘elephant’]
[‘duck’, ‘elephant’]
[‘camel’, ‘duck’]
[‘ant’, ‘bison’, ‘camel’, ‘duck’, ‘elephant’]
What is the output?
const words = ['spray', 'limit', 'elite', 'exuberant', 'destruction', 'present']; const result = words.filter(word => word.length > 6); console.log(result);
Array [“exuberant”, “destruction”, “present”]
What is the output?
const array = [1, 2, 3, 4, 5]; // Checks whether an element is even const even = (element) => element % 2 === 0; console.log(array.some(even));
true
What is the output?
const isBelowThreshold = (currentValue) => currentValue < 40; const array1 = [1, 30, 39, 29, 10, 13]; console.log(array1.every(isBelowThreshold));
true
What is the output?
const array1 = [1, 4, 9, 16]; // Pass a function to map const map1 = array1.map(x => x * 2); console.log(map1);
Array [2, 8, 18, 32]
What is the output?
const kvArray = [ { key: 1, value: 10 }, { key: 2, value: 20 }, { key: 3, value: 30 }, ]; const reformattedArray = kvArray.map(({ key, value }) => ({ [key]: value })); console.log(reformattedArray); console.log(kvArray);
[{ 1: 10 }, { 2: 20 }, { 3: 30 }]
[
{ key: 1, value: 10 },
{ key: 2, value: 20 },
{ key: 3, value: 30 }
]
What is the output?
const array1 = [5, 12, 8, 130, 44]; const found = array1.find((element, index, arraycopy) => element > 10); console.log(found);
12
What is the output?
const arr1 = [0, 1, 2, [3, 4]]; console.log(arr1.flat()); const arr2 = [0, 1, 2, [[[3, 4]]]]; console.log(arr2.flat(2));
[0, 1, 2, 3, 4]
[0, 1, 2, [3, 4]]
What is the output?
const animals = ['ant', 'bison', 'camel', 'duck', 'elephant']; console.log(animals.slice(2)); console.log(animals.slice(2, 4));
[‘camel’, ‘duck’, ‘elephant’]
[‘camel’, ‘duck’]
What is the output?
function doSomething(){ console.log('message ' + message); var message = 'hello '; }
message undefined
What is the output?
console.log(hoist); var hoist = 'hi';
undefined
What are the falsy values?
false
0
-0
0n
‘’
null
undefined
NaN
What function can be used to determine the boolean value of any variable?
Boolean()
How is the strict equality operator different from the loose equality operator?
The strict equality operator verifies that both the value and data type of the operands match
What does JSON stand for?
JavaScript Object Notation
What methods can be used to change the value of the keyword ‘this’?
call, apply, and bind
~~~
thing.call(this, param1, param2, param3);
thing.bind(this, param1, param2, param3)();
thing.apply(this, [param1, param2, param3]);
~~~
When working with an iterator or generator, what method is used to access the next value?
next()
What are the two ways to access an object property?
Dot notation and bracket notation.
What is the object called that another object inherits from?
Prototype
What method is used to identify if an object owns a particular property and is not borrowing it from a prototype?
hasOwnProperty()
What are the two ways of creating a class in JavaScript?
Class declaration
Class expression
What keyword causes a class to inherit from another class?
extends
What type of inheritance is used when using a class constructor?
Prototypal inheritance
What are the three types of variable scopes in JavaScript?
Global scope
local scope(function scope)
block scope
What are the keywords that enable the creation of block scoped variables?
let and const
What are the two main types of execution context in JavaScript?
Global execution context
Function execution context
What is the syntax for exporting function ‘composeData’ as the default?
export default composeData;
What is the correct statement for importing function ‘multiply’ and object ‘data’ from ‘./util.js’?
import { multiply, data} from ‘./util.js’;
What does the statement that modules are imported as ‘live bindings’ mean?
Values imported from a module are updated by that module. If a value is changed, it will be reflected in the code that imports and uses it.
What is the correct statement for importing function ‘multiply’ and object ‘data’ from ‘./util.js’?
import { multiply, data} from ‘./util.js’;
What does the statement that modules are imported as ‘live bindings’ mean?
Values imported from a module are updated by that module. If a value is changed, it will be reflected in the code that imports and uses it.
How many arguments are passed to a decorator function when it is being used to decorate a class?
1
What is the argument that is responsible for the writable attribute of a class property?
descriptor
How many arguments are passed to a decorator function when it is being used to decorate a class method?
3
What are the two approaches for handling events in JavaScript?
Adding an event listener
Using an ‘onevent’ handler.
What statement is used to create a custom event?
new CustomEvent(‘eventName’, {optionalDetailsPlacedInObject})
What is event bubbling?
The target element receives the event and then any handlers in the elements ancestry will each receive the event in turn.
Which API can be used to render shapes on an HTML page?
Canvas API
Which API can be used to retrieve JSON strings over a network?
Fetch API
Which event is triggered when clicking on either the previous or next page button on a web browser?
The window’s popstate event
What does the DOM represent?
The structure and content of an HTML document.
What command can be used to select all the DOM elements of a particular type?
querySelectorAll()
What property can be used to set the HTML content of a DOM element?
innerHTML
What can be inspected and modified in the Elements panel?
DOM and CSS
Where does one monitor the value of a variable over time?
Watch pane
To check if data has been downloaded, what panel should be used?
Network panel
What command can be used to log an error to the console?
console.error()
How is code execution paused so that variables can be examined?
By creating a breakpoint
Where are the currently defined local and global variables displayed?
In the scope pane
What is the main advantage of asynchronous code?
It can execute separately from the main code without blocking it.