Podcast
Questions and Answers
What will be the output of the following JavaScript code snippet?
alert('This is an important message!');
What will be the output of the following JavaScript code snippet?
alert('This is an important message!');
- A confirm box
- No output
- A prompt box
- An alert box with the message 'This is an important message!' (correct)
Which of the following is an assignment operator in JavaScript?
Which of the following is an assignment operator in JavaScript?
- +
- *
- ==
- = (correct)
In JavaScript's logical operators, what will be the result of true || false
?
In JavaScript's logical operators, what will be the result of true || false
?
- null
- true (correct)
- false
- undefined
Which control structure in JavaScript is used for selecting between two different paths based on a condition?
Which control structure in JavaScript is used for selecting between two different paths based on a condition?
Under which category do the following operators fall in JavaScript: '===', '!==', '>=', '<'?
Under which category do the following operators fall in JavaScript: '===', '!==', '>=', '<'?
Which JavaScript operator can be used to assign a value only if a condition is true?
Which JavaScript operator can be used to assign a value only if a condition is true?
Which keyword is used to declare a constant variable in JavaScript?
Which keyword is used to declare a constant variable in JavaScript?
What is the correct way to initialize a variable 'age' to 20 in JavaScript?
What is the correct way to initialize a variable 'age' to 20 in JavaScript?
Which of the following is NOT a valid way to declare multiple variables in JavaScript?
Which of the following is NOT a valid way to declare multiple variables in JavaScript?
When assigning a value to a variable in JavaScript, what symbol is used for comparison?
When assigning a value to a variable in JavaScript, what symbol is used for comparison?
Which of the following is a correct way to declare and initialize a constant variable in JavaScript?
Which of the following is a correct way to declare and initialize a constant variable in JavaScript?
What message will be displayed if the 'mark' variable is 45 in the first code snippet?
What message will be displayed if the 'mark' variable is 45 in the first code snippet?
In the second code snippet, what message will be displayed if the user enters -7?
In the second code snippet, what message will be displayed if the user enters -7?
What will be the output if the condition in line 38 is false?
What will be the output if the condition in line 38 is false?
Are the control structures in lines 37 and 38 of the text equivalent?
Are the control structures in lines 37 and 38 of the text equivalent?
What would be the result of the time assignment operation in line 40 of the text?
What would be the result of the time assignment operation in line 40 of the text?
If the 'time' variable is 10, what would be the output of the condition in line 40 of the text?
If the 'time' variable is 10, what would be the output of the condition in line 40 of the text?
Study Notes
Variables and Data Types
- In JavaScript, all numbers are represented as floating-point values.
- Variables are declared using the
var
andlet
keywords. - Examples of variable declarations:
var age;
,var smallNumber;
,var initial;
,var name;
,var isPassed;
,var num1, num2, num3;
- Standards for variable names:
- No spaces
- No JavaScript reserved keywords
- Meaningful names
- Use camel case
- Variable initialization:
var age = 20;
,var height = 5.5;
,var initial = "K";
,var name = "Kamal";
,var isPassed = true;
- Assigning values to variables:
age = 20;
,height = 5.5;
,initial = "K";
,name = "Kamal";
,isPassed = true;
Constants
- The
const
keyword was introduced in ES6 (ES2015) to create constants. - Example:
const x = 5;
- Constants cannot be changed:
x = 10;
would result in an error. - Constants must be initialized when declared:
const x;
would result in an error.
Using Variables
- Reading and using variable values:
var age = 20;
,document.write(age);
,age = 25;
,document.write("Modified age = " + age);
- JavaScript is a weakly typed language.
JavaScript Pop-up Boxes
- Alert box:
alert("This is an important message !");
- Confirm box:
var response = confirm("Press a button");
- Prompt box:
var name = prompt("enter your name", "Sir");
Operators
- Arithmetic Operators
- Assignment Operators
- Comparison Operators
- Logical Operators
Control Structures
Selection/Branching
- If-else statements: used to divide the algorithm execution path into branches based on conditions.
- Conditions produce Boolean results.
- Simple if-else example:
- If the mark is greater than or equals 50, display a message "Pass", else display a message "Fail".
- Code:
if (mark >= 50) { document.write("Pass"); } else { document.write("Fail"); }
Repetition/Iteration/Looping
- While loop
- For loop
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Description
Test your knowledge of variable initialization, assignment, and data types in JavaScript with this quiz. Practice understanding the output of different variable and data type operations in JavaScript.