JavaScript Quiz Flashcards

0.0(0)
studied byStudied by 1 person
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/39

flashcard set

Earn XP

Description and Tags

Flashcards based on JavaScript quiz questions and answers.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

40 Terms

1
New cards

Which of the following is a valid for loop in JavaScript?

for (var i = 0; i < 5; i++) { console.log(i); }

2
New cards

What is an example of a keyboard event in JavaScript?

keydown

3
New cards

What does the following code do? keyDownMethod(keyFunction); function keyFunction(event) { console

It logs the key pressed on the keyboard

4
New cards

How many value pairs are logged by this loop? for (var i = 0; i < 3; i++) { for (var j = 0; j < 2; j++) { consol

6

5
New cards

What does the && operator represent?

Logical AND

6
New cards

What is the purpose of nested for loops?

To perform repetitive tasks in a grid-like structure

7
New cards

What is a boolean value?

A value that is either true or false

8
New cards

How can you make a for loop count backwards from 10 to 0?

for (var i = 10; i >= 0; i--)

9
New cards

How would you fix this infinite loop? var counter = 0; while (counter < 5) { console.log(counter); }

Add counter++; inside the loop

10
New cards

What does this code print? for (int i = 0; i < 10; i++) { console.log(Randomizer.nextInt(1, 2)); }

It prints either 1 or 2 randomly each of ten times

11
New cards

What's the bug in this code? var count = 0; while (count < 5) { console.log(count); }

The loop will run infinitely

12
New cards

Why are random numbers useful in programming?

They help simulate unpredictable real-world events

13
New cards

What's the bug in this loop-and-a-half structure? while (true) { var input = readLine("Enter a number:");

readLine() doesn't return a number

14
New cards

Which scenario is a good use of a loop-and-a-half?

Searching through a list until a specific item is found

15
New cards

Which statement about infinite loops is true?

They can cause the program to freeze or crash

16
New cards

What does this do-while loop output if number is initially 5?

5

17
New cards

What is the output of addNumbers(5, 10)?

15

18
New cards

What is the output of this code? multiply(2, 5);

10

19
New cards

What does double(3) return?

6

20
New cards

What will isEven(4) return?

true

21
New cards

How many parameters can a function take?

As many as you want

22
New cards

Why use a function with parameters rather than fixed values?

To allow flexibility and reuse of the function with different inputs

23
New cards

What happens if you define parameters but call the function without arguments?

The parameters will be undefined

24
New cards

Which is a function with multiple parameters?

function calculateArea(width, height) { return width * height; }

25
New cards

How do local variables help organize code?

They prevent naming conflicts between different parts of the program

26
New cards

What is a local variable?

A variable that is declared within a function and only accessible within that function

27
New cards

What does this code output? var globalVar = "I am a variable."; function testScope() { console.log(globa

"I am a variable."

28
New cards

Why are APIs important for developers?

They allow for code reuse and simplify complex operations

29
New cards

Which variable should be declared globally?

A constant value used throughout the program

30
New cards

What is an API (Application Programming Interface)?

A set of functions and tools that allow different software components to communicate

31
New cards

How is Karel's move() an example of an API?

It abstracts complex movement logic into a simple function call

32
New cards

What will this code output? var count = 0; function increment() { var myLocal = count; count++; } increm

1

33
New cards

Which task would require traversing a list?

Finding out how many even numbers there are in the list

34
New cards

What is the length property of an array used for?

To determine the number of elements in the array

35
New cards

What will this code print? var arr = [1, 2, 3, 4]; arr[1] = arr[3] - arr[1]; println(arr);

[1, 2, 3, 4]

36
New cards

"Dali" is located at which index in this list: ["Ada", "Bao", "Cedric", "Dali", "Elena"]

3

37
New cards

What should replace to print all list items?

i < list.length

38
New cards

What is the value of index in this code?

1

39
New cards

How to remove the last item in an array and store it?

var lastTask = tasks.pop();

40
New cards

Which element is at index 1 in ["carrots", "peas", "sprouts", "okra"]?

"peas"