JavaScript Basics: Variables, Functions, Loops, Arrays, Objects Quiz

GoodlySaxophone avatar
GoodlySaxophone
·
·
Download

Start Quiz

Study Flashcards

5 Questions

What will be the output of the following JavaScript code snippet?

"53"

What is a function in JavaScript?

A block of reusable code

Which type of loop in JavaScript repeats an action while a certain condition remains true?

for loop

What is an array in JavaScript?

An ordered collection of values

How do you call a function in JavaScript?

functionName(args);

Study Notes

JavaScript Basics: Variables, Functions, Loops, Arrays, Objects

Variables

Variables are named storage locations in JavaScript that hold values. They are declared with the let keyword, followed by the variable name. Here's an example:

let variableName;   // Declare a variable without initializing it
variableName = 5;    // Initialize a variable
console.log(variableName);  // Output: 5

Functions

Functions define blocks of reusable code. They consist of a name, optional parameters, and a body containing zero or more statements. Here's a simple example:

function functionName(parameter1, parameter2, ...) {
  // Body of the function goes here
}

To call a function, simply execute its name followed by any necessary arguments:

functionName(argument1, argument2, ...);

Loops

Loops repetitively perform an action while certain conditions remain true. Some types of loops include for, while, and do-while. Here's an example of a for loop:

for (initializer; condition; incrementor) {
  statement;
}

And here's a typical while loop:

while (condition) {
  statement;
}

Arrays

Arrays are ordered collections of values that can contain multiple items of the same or different types. They're created with square brackets:

const arrayName = [];  // Create an empty array
arrayName[index] = item;  // Set an item in the array
console.log(arrayName);  // Output: [...items]

Objects

Objects are powerful data structures, capable of holding properties and methods. They're constructed with curly braces or literal notation:

const objectName = {};  // Create an empty object
objectName.property = value;  // Add a property to the object
objectName.method = () => { };  // Add a method to the object
console.log(objectName);  // Output: {...properties}

These fundamental aspects of JavaScript enable dynamic scripting, allowing developers to create complex programs that adapt to changing environments and user interactions.

Test your knowledge of JavaScript fundamentals including variables, functions, loops, arrays, and objects with this quiz. Explore how to declare variables, define functions, work with different types of loops, manipulate arrays, and create objects in JavaScript.

Make Your Own Quizzes and Flashcards

Convert your notes into interactive study material.

Get started for free
Use Quizgecko on...
Browser
Browser