Introduction to JavaScript Basics Quiz

JoyousRhinoceros avatar
JoyousRhinoceros
·
·
Download

Start Quiz

Study Flashcards

10 Questions

  1. What is the purpose of JavaScript in web development?

JavaScript is a programming language used to create dynamic content on web pages, allowing for interactive and responsive user experiences.

  1. How are variables declared in JavaScript? Provide examples.

Variables in JavaScript can be declared using 'let' for mutable variables and 'const' for immutable variables. For example, let name = 'John'; const age = 25;

  1. What is the syntax for an if statement in JavaScript? Provide an example.

The syntax for an if statement in JavaScript is 'if (condition) { // code block } else { // code block }'. For example, if (age >= 18) { console.log('You are an adult'); } else { console.log('You are a minor'); }

  1. How are functions declared and called in JavaScript? Provide an example.

Functions in JavaScript are declared using the 'function' keyword, and called by using the function name followed by parentheses. For example, function greet(name) { return 'Hello, ' + name + '.'; } let greeting = greet('Alice'); console.log(greeting);

  1. What is the difference between global and local variables in JavaScript? Provide an example.

Global variables are declared outside of any function, and can be accessed and modified throughout the program. Local variables are declared within a function and can only be accessed and modified within that function. For example, let globalVar = 'I'm global'; function exampleScope() { let localVar = 'I'm local'; console.log(globalVar); console.log(localVar); } exampleScope();

What are the three basic data types in JavaScript? Provide examples for each.

The three basic data types in JavaScript are: strings (e.g. 'John'), numbers (e.g. 25), and booleans (e.g. true).

How are arrays created and manipulated in JavaScript? Provide an example.

Arrays in JavaScript are created using square brackets, and can be manipulated using methods like push() and pop(). For example: let fruits = ['apple', 'orange', 'banana']; fruits.push('grape'); fruits.pop();

What is the syntax for a for loop in JavaScript? Provide an example.

The syntax for a for loop in JavaScript is: for (initialization; condition; increment) { // code block }. For example: for (let i = 0; i < 5; i++) { console.log(i); }

How are functions scoped in JavaScript? Provide an example.

In JavaScript, functions have access to variables in their containing scope. For example, a function can access global variables and its own local variables within its scope.

What is the purpose of the alert() function in JavaScript? Provide an example.

The alert() function in JavaScript is used to display a message in a dialog box. For example: alert('Hello, World.');

Test your knowledge of JavaScript basics with this quiz covering programming language introduction, basic syntax, variables, data types, operators, and control flow.

Make Your Own Quizzes and Flashcards

Convert your notes into interactive study material.

Get started for free

More Quizzes Like This

JavaScript Basics Quiz
10 questions

JavaScript Basics Quiz

MagicalBlessing avatar
MagicalBlessing
Dynamic JavaScript
5 questions

Dynamic JavaScript

AppreciativeDesert avatar
AppreciativeDesert
Use Quizgecko on...
Browser
Browser