1 Answers
📚 Quick Study Guide: JavaScript Basic Syntax
- 💡 Variables: Use
var,let, orconstto store data. Example:let score = 100; - ✍️ Statements: JavaScript instructions are called statements. Most end with a semicolon (
;). - 💬 Comments: Use
//for single-line comments or/* ... */for multi-line comments. Comments make your code easier to understand for humans and are ignored by the computer. - 🔢 Data Types: Common types include Numbers (e.g.,
10,3.14), Strings (text like"Hello World"), and Booleans (trueorfalse). - ➕ Operators: Symbols that perform operations. For example,
+(addition),-(subtraction),*(multiplication),/(division). The=sign is the assignment operator. - 💻 Output: To show information in the browser's console (a special area for developers), use
console.log("Your message here"); - ✅ Naming Rules: Variable names cannot start with a number and cannot contain spaces. They are case-sensitive (
myVaris different frommyvar).
📝 Practice Quiz
1. Which keyword is commonly used to declare a variable in JavaScript?
variablevarstringdeclare
2. What is the main purpose of a semicolon (;) at the end of a statement in JavaScript?
- To make the code bold
- To separate statements and indicate the end of a line of code
- To start a new paragraph
- To create a comment
3. How do you write a single-line comment in JavaScript?
# This is a comment<!-- This is a comment -->// This is a comment/* This is a comment */
4. Which command is used to display output or messages in the browser's console?
print("hello");display("hello");console.log("hello");show("hello");
5. How do you correctly assign the text value "JavaScript" to a variable named language?
language = JavaScript;language: "JavaScript";language = "JavaScript";"JavaScript" = language;
6. Which of the following is a valid variable name in JavaScript?
1stNumbermy-variable_userNamevar
7. What does the + operator do when used with two numbers in JavaScript?
- Subtracts them
- Divides them
- Adds them
- Multiplies them
Click to see Answers
1. B (var is a common keyword, let and const are also used for variable declaration)
2. B
3. C
4. C
5. C
6. C
7. C
Join the discussion
Please log in to post your answer.
Log InEarn 2 Points for answering. If your answer is selected as the best, you'll get +20 Points! 🚀