← Back to JavaScript Course | Chapter 1: Basics & Syntax | Lesson 5 of 12

JS Syntax

Every language, spoken or programming, has grammar rules that make it understandable, subjects, verbs, and punctuation all have to line up in a way both sides agree on. JavaScript syntax is that grammar, it defines how values, operators, expressions, and keywords fit together into valid instructions the browser can actually run. Get the grammar wrong, and the engine simply cannot understand what you meant. Once you're comfortable with JavaScript's basic building blocks, values, operators, and identifiers, reading any script, including the ones powering the tutorials on cookiescursor.com, becomes far less intimidating.
Syntax
javascript
let variableName = value;
function functionName(parameter) {
  return value;
}
object.property

Values

Value डेटा का एक अकेला टुकड़ा है जिसके साथ JavaScript काम कर सकती है, जैसे कोई संख्या, कोई text, या true और false, और values वह कच्चा माल हैं जिसे हर JavaScript program संचालित करता है।

Note: JavaScript में values दो तरह के होते हैं, literal values जो आप सीधे लिखते हैं जैसे 5 या hello, और variable values जो किसी नाम के तहत store होते हैं।
Warning: Text values must always be wrapped in quotes, forgetting quotes around text is one of the most common beginner syntax errors.

उदाहरण: Values

javascript
// Print `5` to the console
// Print `5` to the console
console.log(5);
// Print "hello" to the console
// Print "hello" to the console
console.log("hello");
// Print `true` to the console
// Print `true` to the console
console.log(true);

Operators

Operators वे symbols हैं जो values पर क्रियाएँ करते हैं, जैसे संख्याएँ जोड़ने या text जोड़ने के लिए +, और variable में value रखने के लिए =, जो किसी expression में values के बीच जोड़ने वाली कड़ी बनाते हैं।

Note: वही + operator अपने आसपास के values के आधार पर अलग व्यवहार करता है, संख्याएँ जोड़ता है पर text को अगल-बगल जोड़ता है।
Warning: Mixing a number and a string with + can produce surprising results, since JavaScript often converts the number into text rather than adding it.

उदाहरण: Operators

javascript
console.log(2 + 3);
console.log("Hello" + " World");

Expressions

Expression कोई भी code का टुकड़ा है जो एक value बनाता है, एक साधारण literal से लेकर operators और function calls के जटिल संयोजन तक, और expressions वे टुकड़े हैं जिनसे statements बनते हैं।

Note: आप हमेशा यह परख सकते हैं कि कोई चीज़ वैध expression है या नहीं यह पूछकर, क्या यह ऐसा value बनाता है जिसे मैं store या log कर सकूँ?
Warning: Not every valid piece of syntax is an expression, a full statement like an if block does not itself produce a usable value.

उदाहरण: Expressions

javascript
let result = 2 + 3 * 4;
console.log(result);

Keywords और Identifiers

Keywords JavaScript में विशेष अर्थ वाले आरक्षित शब्द हैं, जैसे const, function और if, जिन्हें आप अपने नामों के रूप में इस्तेमाल नहीं कर सकते, जबकि identifiers वे कस्टम नाम हैं जो आप अपने code के variables, functions और अन्य हिस्सों के लिए चुनते हैं।

Note: वर्णनात्मक identifier नाम चुनिए, जैसे x की जगह userEmail, आपके code के भावी पाठक, आप खुद भी, इसकी सराहना करेंगे।
Warning: Attempting to use a reserved keyword as an identifier, such as naming a variable const, immediately causes a syntax error.

उदाहरण: Keywords and Identifiers

javascript
const userEmail = "[email protected]";
console.log(userEmail);

Case Sensitivity और camelCase

JavaScript पूरी तरह case sensitive है, यानी userName और username दो बिलकुल अलग identifiers माने जाते हैं, और variables तथा functions के नामकरण की सामुदायिक परंपरा camelCase है, जहाँ पहला शब्द छोटे अक्षरों में और बाद का हर शब्द बड़े अक्षर से शुरू होता है।

Note: पूरे project में camelCase पर एकसमान रहिए, नामकरण शैलियाँ मिलाना code को scan और search करना कठिन बनाता है।
Warning: A typo that only differs in letter case, like calling getUserData() when the function is actually named getUserdata(), causes a reference error rather than a helpful warning.

उदाहरण: Case Sensitivity and camelCase

javascript
// Declare the variable `userName`, set to "Alice"
// Declare the variable `userName`, set to "Alice"
let userName = "Alice";
// Declare the variable `username`, set to "Bob"
// Declare the variable `username`, set to "Bob"
let username = "Bob";
// Print `userName, username` to the console
// Print `userName, username` to the console
console.log(userName, username);
Live Example
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
🔒

Chapter Quiz — Complete all 12 topics to unlock

0/12 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.