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

JS सिंटैक्स

हर language, चाहे बोली जाने वाली हो या programming की, में grammar के नियम होते हैं जो उसे समझने लायक बनाते हैं, subjects, verbs, और punctuation सबको एक ऐसे तरीके से लाइन में लगना होता है जिस पर दोनों पक्ष सहमत हों। JavaScript syntax वही grammar है, यह तय करती है कि values, operators, expressions, और keywords कैसे मिलकर valid instructions बनाते हैं जिन्हें browser असल में चला सके। grammar गलत हो, तो engine बस यह समझ ही नहीं पाता कि आपका मतलब क्या था। एक बार जब आप JavaScript के बुनियादी building blocks, values, operators, और identifiers के साथ सहज हो जाते हैं, तो cookiescursor.com पर tutorials चलाने वाले scripts सहित किसी भी script को पढ़ना कहीं कम डरावना हो जाता है।
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. #}
आम गलतियां
  1. class या return जैसे किसी reserved keyword को variable name की तरह इस्तेमाल करना, जो तुरंत एक syntax error का कारण बनता है।
  2. case sensitivity को मिला देना, JavaScript myVariable और myvariable को दो पूरी तरह अलग identifiers मानता है।
  3. किसी identifier को number से शुरू करना, valid identifiers को letter, underscore, या dollar sign से शुरू होना चाहिए।
चैप्टर सारांश
  • Values, operators, expressions, और keywords JavaScript syntax के fundamental building blocks हैं।
  • Identifiers variables, functions, और दूसरी entities को दिए गए नाम हैं, और वे specific naming rules follow करते हैं।
  • JavaScript case sensitive है, और camelCase variables और functions के लिए standard naming convention है।
ब्राउज़र सपोर्ट

Core JavaScript syntax rules, values, operators, expressions, और identifier rules, language standard का हिस्सा हैं और हर browser में समान रूप से व्यवहार करते हैं।

🔒

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.