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.
When a promise is returned, what method is used to respond to a successful resolution?
The .then() method
How are errors handled in an async function?
Using a try…catch statement
What does the runtime engine use to store and manage the functions to run?
Call Stack
What pushes a message from the message queue to the call stack for processing?
Event Loop
What are the three ways of specifying events to monitor for an object?
Event name
Event type
Array
Which method can be used to create a new instance of http.Server in Node.js?
http.createServer()
Which method can be used to read a file asynchronously in Node.js?
fs.readFile()
Which module can be used in Node.js to emit and handle events?
The ‘events’ module
Which Node.js command can be used to run a JavaScript file named script.js?
node script.js
Which npm command can be used to install the webpack library as a development dependency?
npm install webpack –save-dev
Which Node.js command can be used to check the syntax of the code without execution?
node –check
What are the three types of modules that can be included in a Node.js application?
Core
local
third-party modules
Which core module can be used to work with the file system in Node.js?
The ‘fs’ module
Which third-party module can be used to handle incoming HTTP requests in Node.js?
Express
When following the semantic versioning spec, how should the version number of a package be updated in case of a patch release?
The third digit of the version number should be incremented. For example, 1.0.3 should be changed to 1.0.4.
Which command allows checking if there are installed packages that are outdated?
npm outdated
Which command can be used to update an npm package named ‘lodash’ that is installed locally?
npm update lodash
What console API method can be used to test an assertion?
console.assert()
What is a false negative?
The test instance failed due to a defect in the test, not the code being tested.
In which testing approach is the internal structure of the application not known?
Black-box testing
Which 3 statements will produce a Boolean value of True?
let val1 = 100; let val2 = '100';
A. val1 || val2;
B. val1 == val2;
c. !!val2;
d. val1 && val2;
e. val1 === Number(val2);
val1 == val2;
!!val2;
val1 === Number(val2)
Which would result in NaN being assigned to num?
A. const num = 1/ Number(‘true’)
B. const num = 1/ new Number(true)
C. const num = 1/ Number(‘1000’)
D. const num = 1/ false
const num = 1/ Number(‘true’)
____ is a library with the ability to perform deep comparisons between two objects with the _.isEqual() method
lodash
How any parameters are passed to a decorator function that is used to decorate a class method?
Three
What is the first argument passed to a decorator function that is used to decorate a class method?
target
What is the second argument passed to a decorator function that is used to decorate a class method?
name
What is the third argument passed to a decorator function that is used to decorate a class method?
descriptor
What values does the Promise state property have?
Pending
Rejected
Fulfilled
What is the difference between slice and splice?
Slice returns a new array from the original
Splice adds/removes from the original
What does the unshift() method do?
The unshift() method adds one or more elements to the beginning of an array and returns the new length of the array.
What does the shift() method do?
The shift() method removes the first element from an array and returns that removed element. This method changes the length of the array.
Given this code, how do you retreive only the directory of the given file? (choose 2)
~~~
const path = require(‘path’);
const file = ‘/employees/person.txt’;
~~~
A. path.dirname(file);
B. path.normalize(file).dir;
C. path.parse(file).dir;
D. path.dir(file);
path.dirname(file);
path.parse(file).dir;
What are 3 ways to create Objects?
Object Literal
Object Constructor
Object.create
For var x, how do you create a new object as a literal?
var x = {}
For var x, how do you create a new object as constructor?
var x = new Object()
For var x, how do you create a new object with .create?
var obj = { name : "foo" } var x = Object.create(obj);
What two ways can you call typeof?
typeof operand typeof(operand)
What is the output?
typeof (typeof 1)
“string”
What is the output?
typeof !!(-1)
“boolean”
What is the output?
typeof function(){}
“function”
What is the output?
typeof new Date()
“object”
What is the output?
typeof null
“object”
What is the output?
Number(39)
39
What is the output?
Number(undefined)
NaN
What is the output?
Number('hello')
NaN
What is the output?
Number(" 45 ")
45
What is the output?
Number("\t")
0
What is the output?
Number('3x')
NaN
What is the output?
Number(null)
0
What is the output?
Number(false)
0
What is the output?
Number(true)
1
What is the output?
Number([])
0
What is the output?
Number(['33'])
33
What is the output?
Number(['33', '32'])
NaN
What is the output?
Boolean(2)
true
What is the output?
Boolean({})
true
What is the output?
Boolean([])
true
What is the output?
Boolean('2')
true
What is the output?
Boolean('')
false
What is the output?
Boolean(null)
false
What is the output?
Boolean(0)
false
What is the output?
Boolean(undefined)
false
What is the output?
Boolean(false)
false
What is the output?
Boolean(NaN)
false
What is the output?
Boolean(0n)
false
What is the output?
Boolean(1324n)
true
What is the output?
100 + 'world'
‘100world’
What is the output?
'foo' + 100
‘foo100’
What is the output?
100 + null + 30 + 'foo'
‘130foo’
What is the output?
100 + 400 + undefined + 'foo'
‘NaNfoo’
What is the output?
var x = {} x+'foo'
“[object Object]foo”
What is the output?
100 == '100'
true
What is the output?
100 === '100'
false
What is the output?
true == 'true'
false
What is the output?
NaN === NaN
false
What is the output?
-0 === 0
true
What is the output?
Object.is(-0, 0)
false
What is the output?
s() var s = function{ console.log('hi); }
uncaught error s is not a function
What is the output?
"use strict"; x = 3.14;
uncaught syntax error: x is not defined
What is the output?
"use strict"; var x = 3.14; delete x;
uncaught syntax error: delete of an unqualified identifier in strict mode
What is the output?
"use strict"; function x (p1, p1){};
uncaught syntax error: duplicate parameter name not allowed in this context
What is the output?
var func = new Function('a', 'b', 'return a*b'); func(4,3);
12
What is the output?
[...'hello']
[‘h’,’e’,’l’,’l’,’o’]
What is the output?
var employee = {fName: 'hi', lName : 'hello'}; var {fName, lName} = employee fName; lName;
hi
hello
What is the output?
function outer(){ var counter = 0; return function inner(){ counter += 1 return counter }} var counter = outer(); counter(); counter(); counter();
3
What does location.assign do?
loads a new document
What does Navigator.online do
returns true / false on if connected to internet
What way is this Object being instantiated?
var x = {} var detail = { name: "nikhil" }
Object literal
What way is this Object being instantiated?
var x = new Object() x.name = "dude" console.log(x)
Object constructor
What way is this Object being instantiated?
var obj = { name: "dude" } var newObj = Object.create(obj)
Object.create() method
What is the output?
typeof NaN
Number
What is the output?
typeof 0
Number
What is the output?
typeof “true”
String
What is the output?
var x typeof x
undefined
What is the output?
typeof null
object
What is the output?
typeof {}
object
What is the output?
typeof !!(1)
Boolean
What is the output?
typeof function () { }
function
What is the output?
typeof new Date()
Object
What is the output?
String(undefined)
‘undefined’
What is the output?
String(true)
‘true’
What is the output?
Number(Symbol())
TypeError thrown, as symbols cannot be converted to a Number
What is the output?
String([])
’’
What is the output?
String({})
[object Object]
What is the output?
String([a:1,b:2])
[object Object]
What is the output?
String([5,10,15])
5,10,15
What is the output?
String(null)
‘null’
What is the output?
String(Symbol('hello'))
Symbol(‘hello’)
What is the output?
Number(null)
0
What is the output?
Number(undefined)
NaN
What is the output?
Number('hello')
NaN
What is the output?
Number([])
0
What is the output?
Number([33, 33])
NaN
What is the output?
Number(['52'])
52
What is the output?
Boolean('')
false
What is the output?
Boolean(' ')
true
What is the output?
Boolean(undefined)
false
What is the output?
Boolean(null)
false
What is the output?
Boolean(NaN)
false
What is the output?
NaN == NaN
false
What is the output?
NaN === NaN
false
What is the output?
- 0 == 0
true
What is the output?
- 0 === 0
true
What is the output?
[] === []
false
What is the output?
[] == []
false
What is the output?
Object.is(100, "100")
false
What is the output?
var x = 10 console.log(x++)
10
What is the output?
var x = 10 x++ console.log(x);
11
What is the output?
var x = [] var y = x x === y
true
What is the output?
"Hello" + "World" + "16546542"
‘HelloWorld16546542’
What is the output?
100 + "world"
‘100world’
What is the output?
100 + null + 20 + "world"
‘120world’
What is the output?
true + 1 + "hey"
‘2hey’
What is the output?
undefined + 2
NaN
What is the output?
null + 2
2
What is the output?
100 + 200 + undefined + "hey"
NaNhey
What is the output?
undefined + 2 + 'no'
NaNno
What is the output?
JSON.parse("'str'")
Uncaught SyntaxError: Unexpected token ''' "'str'" is not valid JSON at JSON.parse (<anonymous>) at <anonymous>:1:6
What is the output?
JSON.parse("str")
Uncaught SyntaxError: Unexpected token 's', "str" is not valid JSON at JSON.parse (<anonymous>) at <anonymous>:1:6
What is the output?
JSON.parse('str')
Uncaught SyntaxError: Unexpected token 's', "str" is not valid JSON at JSON.parse (<anonymous>) at <anonymous>:1:6
What is the output?
'"' JSON.parse('"str"')
‘str’
What command is used to install pre-reqs for this code?
const fs = require('fs') const _ = require('lodash')
npm i lodash
npm install lodash
note: fs comes with Node.js so this is redundant
What is a black box test?
A test that only considers the external behavior of the system
What is a white box test?
A method used to test a software taking into consideration its internal functioning
What javascript statement can be used to insert a ‘newelementdiv’ after ‘markerelement’?
document.body.insertBefore(newelementdiv, markerElement.nextSibling)
Which pane in the browser Devtools shows information about the defined local and global variables and their values?
- Global Pane
- Scope Pane
- Variables Pane
- Breakpoints Pane
Scope Pane
In package.json, what versions can be installed with ~
~1.2.3
releases from 1.2.3 to <1.3.0.
In package.json, what version will be installed with ~2.2.0
- 2.2.3
- 3.0.1
- 2.2.1
- 2.3.1
2.2.3
In package.json, what versions can be installed with ^
^1.2.3
releases from 1.2.3 to <2.0.0
What will advance to line 2 in execution?
- node app.js, debug next
- node app.js, debug
- node debug appj.js, n
- node inspect app.js, next
node inspect app.js, next
How many arguments does the reduce() method take? What do the argument(s) do?
2 required, can be passed as a function or an array
//function const numbers = [15.5, 2.3, 1.1, 4.7]; document.getElementById("demo").innerHTML = numbers.reduce(getSum, 0); function getSum(total, num) { return total + Math.round(num); } //array const numbers = [175, 50, 25]; document.getElementById("demo").innerHTML = numbers.reduce(myFunc); function myFunc(total, num) { return total - num; }
What is the output?
Number.isNaN(‘hello’)
false
this is false because Number.isNan method only checks if the value is equal to NaN
What is the output?
isNaN(‘hello’)
true
this is true because the global method isNaN checks whether the passed value is not a number or cannot be converted into a Number
What is the output?
const bool = true; const str = '5'; console.log(bool == 5);
false
What are 3 ways to loop through arrays?
for(let i = 0; i < customers.length; i ++) {} for(const index in customers) {} customers.forEach(customer =>{})
What is the output?
const numbers = [3, 1, 4, 1, 5]; const sorted = numbers.sort((a, b) => a - b); sorted[0] = 10; console.log(numbers[0]);
10
What is the output?
const numbers = [3, 1, 4, 1, 5]; const sorted = [...numbers].sort((a, b) => a - b); sorted[0] = 10; console.log(numbers[0]);
3
What is the output?
const bool = false; const str = '5'; console.log(bool & str); console.log(bool && str);
0 false
What are the characteristics of a white box test?
- Testing can be automated
- Testing a particular functionality is less complex
- It represents a functional test of the software
- The focus is on testing structures, objects and functions
- Testing is mostly performed by software developers
- Testing can be automated
- The focus is on testing structures, objects and functions
- Testing is mostly performed by software developers
In nodeJS, how do you write a body JSON?
response.write(jsonStr);