-
Hajipur, Bihar, 844101
Hajipur, Bihar, 844101
JS Basics
JS Variables & Operators
JS Data Types & Conversion
JS Numbers & Math
JS Strings
JS Dates
JS Arrays
JS Control Flow
JS Loops & Iteration
JS Functions
JS Functions
Function Definitions
Function Parameters
Function Invocation
Function Call
Function Apply
Function Bind
Function Closures
JS Arrow Function
JS Objects
JS Objects
JS Object Properties
JS Object Methods
JS Object Display
JS Object Constructors
Object Definitions
Object Get / Set
Object Prototypes
Object Protection
JS Classes & Modules
JS Async Programming
JS Advanced
JS Destructuring
JS Bitwise
JS RegExp
JS Precedence
JS Errors
JS Scope
JS Hoisting
JS Strict Mode
JS this Keyword
JS HTML DOM
DOM Intro
DOM Methods
DOM Document
DOM Elements
DOM HTML
DOM Forms
DOM CSS
DOM Animations
DOM Events
DOM Event Listener
DOM Navigation
DOM Nodes
DOM Collections
DOM Node Lists
JS BOM (Browser Object Model)
JS Window
JS Screen
JS Location
JS History
JS Navigator
JS Popup Alert
JS Timing
JS Cookies
Web Storage API
JS Web APIs
JS AJAX
AJAX Intro
AJAX XMLHttp
AJAX Request
AJAX Response
AJAX XML File
AJAX PHP
AJAX ASP
AJAX Database
AJAX Applications
AJAX Examples
JS JSON
JSON Intro
JSON Syntax
JSON vs XML
JSON Data Types
JSON Parse
JSON Stringify
JSON Objects
JSON Arrays
JSON Server
JSON PHP
JSON HTML
JSON JSONP
JS Canvas
JS Graphics & Charts
JS Basics
JS Variables & Operators
JS Data Types & Conversion
JS Numbers & Math
JS Strings
JS Dates
JS Arrays
JS Control Flow
JS Loops & Iteration
JS Functions
JS Functions
Function Definitions
Function Parameters
Function Invocation
Function Call
Function Apply
Function Bind
Function Closures
JS Arrow Function
JS Objects
JS Objects
JS Object Properties
JS Object Methods
JS Object Display
JS Object Constructors
Object Definitions
Object Get / Set
Object Prototypes
Object Protection
JS Classes & Modules
JS Async Programming
JS Advanced
JS Destructuring
JS Bitwise
JS RegExp
JS Precedence
JS Errors
JS Scope
JS Hoisting
JS Strict Mode
JS this Keyword
JS HTML DOM
DOM Intro
DOM Methods
DOM Document
DOM Elements
DOM HTML
DOM Forms
DOM CSS
DOM Animations
DOM Events
DOM Event Listener
DOM Navigation
DOM Nodes
DOM Collections
DOM Node Lists
JS BOM (Browser Object Model)
JS Window
JS Screen
JS Location
JS History
JS Navigator
JS Popup Alert
JS Timing
JS Cookies
Web Storage API
JS Web APIs
JS AJAX
AJAX Intro
AJAX XMLHttp
AJAX Request
AJAX Response
AJAX XML File
AJAX PHP
AJAX ASP
AJAX Database
AJAX Applications
AJAX Examples
JS JSON
JSON Intro
JSON Syntax
JSON vs XML
JSON Data Types
JSON Parse
JSON Stringify
JSON Objects
JSON Arrays
JSON Server
JSON PHP
JSON HTML
JSON JSONP
JS Canvas
JS Graphics & Charts
JavaScript syntax is a set of rules that define how programs are written. Learning the basic syntax is essential to avoid errors and write clean, readable code.
A JavaScript statement is a command or instruction that tells the browser to do something.
let x = 5;
console.log(x);
Each line above is a statement. Statements are usually ended with a semicolon ;
, although it's optional in many cases.
JavaScript has reserved keywords used to perform actions:
Keyword | Description |
---|---|
var |
Declares a variable |
let |
Declares a block-scoped variable |
const |
Declares a constant value |
if |
Conditional statement |
for |
Loop |
function |
Defines a function |
JavaScript values are either:
Fixed values (literals): 5
, "Hello"
, true
Variable values: declared with let
, const
, or var
Identifiers are the names you give to variables and functions. They must follow these rules:
Must begin with a letter, underscore _
, or dollar sign $
Cannot start with a number
Case-sensitive
let name = "John";
let Name = "Doe"; // Different from 'name'
Used to perform operations:
let x = 5 + 3; // + is the addition operator
Code blocks are enclosed in curly braces {}
. They group multiple statements together, especially in if
, for
, or function blocks.
if (x > 5) {
console.log("x is greater than 5");
}
Single-line: // This is a comment
Multi-line:
/*
This is a
multi-line comment
*/
Q1. How do you declare a variable city
and assign the value "Delhi"
using JavaScript syntax?
Q2. What is the correct way to write a single-line comment in JavaScript?
Q3. How do you declare two variables x
and y
, assign values 10
and 20
, and add them together in a new variable sum
?
Q4. How can you write a JavaScript block that logs "Good Morning"
only if a variable hour
is less than 12?
Q5. How do you declare a constant named PI
and assign the value 3.14
to it using correct syntax?
Q6. How do you write a multi-line comment in JavaScript explaining what a function does?
Q7. How do you define a function called greet
that logs "Welcome!"
when called?
Q8. What is the correct way to name a variable that stores a user's age, following JavaScript identifier rules?
Q9. How do you use an operator to subtract 5
from 15
and store the result in a variable named difference
?
Q10. How do you write a loop that runs 3 times and logs the index value using proper JavaScript syntax?
Q1: Which of the following is a valid JavaScript variable declaration?
Q2: What symbol is used to start a single-line comment in JavaScript?
Q3: What are JavaScript identifiers used for?
Q4: Which of the following is NOT a valid identifier in JavaScript?
Q5: What does this JavaScript statement do: let x = 5 + 3;?
Q6: What is the purpose of a code block in JavaScript?
Q7: Which character is used to group a block of code in JavaScript?
Q8: Which of the following is a JavaScript keyword?
Q9: What happens if you omit the semicolon in JavaScript?
Q10: Which of the following is a multi-line comment in JavaScript?