24 Questions
What is the purpose of JavaScript comments?
To make the code easy to read and understand
What is the syntax for a single-line comment in JavaScript?
// line to be commented
What is the purpose of the prompt() function in JavaScript?
To display a message to the user
What is the result of a comparison between values in JavaScript?
A boolean value
What is the operator used to check if two values are equal and are of the same type?
===
What is the purpose of the default message in the prompt() function?
To provide a default value for user input
What is the syntax for a multiline comment in JavaScript?
/* comment */
What is the purpose of the assignment operators in JavaScript?
To assign a value to a variable
What is the main advantage of using global variables in JavaScript?
They can be used to store data in one place and access it from anywhere in the code.
Which of the following keywords can be used to declare a variable that can change its data type?
let
What is the purpose of the prompt() function in JavaScript?
To display a dialog with an optional message and take user input.
What will happen if a variable is declared with the let keyword but not initialized?
It will show undefined.
What is the scope of a variable declared with the let keyword?
Block scope.
What is the difference between variables declared with the var and let keywords?
Variables declared with var have a global scope, while variables declared with let have a block scope.
What is the default value of a variable declared with the let keyword but not initialized?
Undefined.
What is the purpose of using global variables in JavaScript?
To store data in one place and access it from anywhere in the code.
What is JavaScript?
A weakly typed language
What is the extension of a JavaScript file?
.js
Which method is used to display an alert box with a specified message?
window.alert()
What is the purpose of the document.write() method?
To print output to the browser's webpage
What is the purpose of the innerHTML property?
To set an inner HTML element
What is the purpose of the console.log() method?
To write a message to the console
How can JavaScript be used?
For both Client-Side and Server-side developments
Where can JavaScript codes be placed in HTML?
Between the script tags
Study Notes
Global Variables
- Global variables are declared outside of function declarations and can be accessed from anywhere in the code.
- They allow storing data in one place and accessing it from anywhere in the code.
Variable Declaration Keywords
-
let
keyword: can change the data type of a variable, and the value declared inside a scope cannot be used outside. -
var
keyword: can change the data type of a variable, and the value declared inside a scope cannot be used outside. -
const
keyword: cannot change the data type of a variable, and the value declared inside a scope cannot be used outside.
Input in JavaScript
- The
prompt()
function is used to take user input in JavaScript, displaying a dialog with an optional message. - The
prompt()
function is part of thewindow
object.
Introduction to JavaScript
- JavaScript is a weakly typed language (dynamically typed).
- JavaScript can be used for client-side and server-side developments.
- JavaScript is both an imperative and declarative type of language.
- JavaScript contains a standard library of objects, such as Array, Date, and Math, and a core set of language elements like operators, control structures, and statements.
Using JavaScript in HTML
- JavaScript code can be written between `
This quiz covers the concept of global variables in programming, including their declaration and usage within functions.
Make Your Own Quizzes and Flashcards
Convert your notes into interactive study material.
Get started for free