JavaScript

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

What will the expression "10" + 5 return?

"105"

What will be the output of "typeof null" in JavaScript?

'object'

Which of the following defines a function that immediately executes upon its declaration?

(function() {}());

Which of the following is the correct operator for exponentiation (raising a number to a power) in JavaScript?

**

Which of the following methods can be used to iterate over an array in JavaScript?

.forEach()

What is a JavaScript method to remove an item from the end of an array?

.pop()

Which of the following are valid ways to add a comment in JavaScript? Select all that apply.

// This is a comment /*This is a comment*/

What will the following code snippet print? let i = 0; while (i < 3) { console.log(i); i++; }

0, 1, 2

What does the following code output? function outer() { let count = 0; function inner() { count += 1; return count; } return inner; } const increment = outer(); console.log(increment()); console.log(increment());

1 2

What is the output of the following code snippet? let x = 10; function example() { let x = 20; console.log(x); } example(); console.log(x);

20 10

What will be the output of the following code snippet? let data = { a: 10, b: 20, c: 30 }; console.log(Object.keys(data).length);

3

What will be the output of the following JavaScript code snippet? let sum = 0; for (let i = 0; i < 5; i++) { if (i % 2 === 0) continue; sum += i; } console.log(sum);

4

What is the term for a function that takes another function as an argument?

Callback function.

In which type of scope can a variable declared with the var keyword be accessed from?

Global scope and function scope.

Which of the following statements is correct regarding the "continue" keyword in JavaScript?

It skips the rest of the loop's current iteration.

What is the result of the following code? let x = 10; let output = (x > 10) ? "Greater" : "Not greater"; console.log(output);

Not greater

Which of the following are primitive data types in JavaScript?

Number String Boolean

Which of the following is used to test multiple expressions/values?

Switch statement

What does the "finally" block in a try/catch/finally structure ensure?

The code inside it executes whether or not an error occurred in the try block.

What is the purpose of the "break" statement in JavaScript?

To exit the current loop or switch statement.

What is the primary purpose of arrow functions in ES6?

To make functions shorter and simpler.

Which of the following is the correct way to check if variable "a" is both greater than "b" and less than "c" in JavaScript?

a > b && a < c

In an array arr, how can you find the index of the first occurrence of the value "banana"?

arr.indexOf("banana")

Which of the following is a way to declare a constant in JavaScript?

const CONSTANT_NAME;

In a switch statement, what keyword is used as a default condition if none of the cases match?

default

Which statement will execute a block of code at least once, and then repeat it while a condition is true?

do { } while (condition)

What will the following code output? if (false) { console.log('True'); } else { console.log('False'); }

false

Which of the following loops will run a block of code a specified number of times in JavaScript?

for

Which of the following can be used to indefinitely repeat a block of code in JavaScript?

for (;;) { }

How would you iterate over all properties of an object obj in JavaScript? for (let prop in obj) { } for (let prop of obj) { } obj.map(prop => { }) obj.forEach(prop => { })

for (let prop in obj) { }

How can you add a new item "grape" to the end of an existing array fruits?

fruits.push("grape");

Which keyword is used to declare a function in JavaScript

function

How can you set a default parameter for a function in ES6 JavaScript?

function myFunc(param = 'default') { }

Which keyword creates a variable that is block-scoped, which means that it exists only within the current block?

let

Which of the following will correctly create an array with three strings in JavaScript?

let arr = ["one", "two", "three"];

How can you define an anonymous function in JavaScript?

let myFunc = function() { };

Which is a way to create an object in JavaScript?

let obj = {}

What is the best practice for declaring a variable in JavaScript?

let variableName;

Which of the following are valid ways to access the value "apple" from the following object? Select all that apply. let obj = { fruit: "apple", vegetable: "carrot" };

obj['fruit'] obj.fruit

How do you produce a value from a function in JavaScript?

return value;

How can you explicitly throw an exception in JavaScript?

throw new Error('Error message')

What will be the output of console.log(1 + 2 === 3) in JavaScript?

true

Which of the following is used to handle exceptions in JavaScript?

try/catch

How can you get the type of a JavaScript variable?

typeof variable

What will the following code snippet output? var x = 1; function foo() { console.log(x); var x = 2; } foo();

undefined

How do you repeat a block of code as long as a specific condition is true?

while (condition) { }

How can you check if variable "x" is NOT equal to a value "y" in both value and type?

x !== y

How do you check if two values are both equal in value and in type in JavaScript?

x === y


Ensembles d'études connexes

Ch.11 - Developing Reports and Proposals

View Set

Intro to Networking Chapter 4: Protocols

View Set

Chapter 9: Ventilatory Assistance

View Set

Geology 103, Final Exam - Kansas State University

View Set

Ch. 34 + 35 Pre-lecture assignment

View Set