Q. What is JavaScript? Its Advantages and Disadvantages.
In English:
JavaScript is a scripting language used to make web pages interactive and dynamic. It helps in controlling the behavior of web pages such as form validation, animations, pop-ups, and event handling. It runs directly inside the web browser.
Advantages:
- Makes web pages interactive and attractive.
- Runs directly in the browser, no need for extra software.
- Increases the speed of web applications.
- Easy to learn and use with HTML.
- Works on both client and server sides (using Node.js).
Disadvantages:
- Code is visible to users, so it is less secure.
- Can be disabled in browsers, which may stop functions.
- Large scripts can slow down the page.
- Browser compatibility issues may occur.
हिन्दी में:
JavaScript एक स्क्रिप्टिंग भाषा है जो वेब पेज को इंटरैक्टिव और डायनेमिक बनाती है। यह वेब पेज के व्यवहार को नियंत्रित करती है, जैसे फॉर्म जाँचना, एनिमेशन, पॉप-अप और इवेंट हैंडलिंग। यह सीधे वेब ब्राउज़र में चलती है।
फायदे:
- वेब पेज को आकर्षक और इंटरैक्टिव बनाती है।
- किसी अतिरिक्त सॉफ्टवेयर की आवश्यकता नहीं होती।
- वेब एप्लिकेशन की गति बढ़ाती है।
- HTML के साथ सीखना और उपयोग करना आसान है।
- क्लाइंट और सर्वर दोनों पर काम कर सकती है (Node.js द्वारा)।
नुकसान:
- कोड यूज़र को दिखाई देता है, इसलिए सुरक्षा कम होती है।
- यदि ब्राउज़र में JavaScript बंद हो, तो कार्य रुक सकते हैं।
- बड़ा स्क्रिप्ट पेज की गति कम कर सकता है।
- अलग-अलग ब्राउज़रों में कोड सही से न चलने की संभावना रहती है।
Q. Difference between Client Side Scripting and Server Side Scripting
In English:
Client Side Scripting and Server Side Scripting are two types of web scripting used to create dynamic web pages. The main difference is where the code runs — on the user’s browser or on the server.
| Client Side Scripting | Server Side Scripting |
|---|---|
| Code runs on the user’s web browser. | Code runs on the web server. |
| Used for user interaction and page design. | Used for database connection and data processing. |
| Executes quickly because no server request is needed. | Slower because it sends requests to the server. |
| Example languages: JavaScript, VBScript. | Example languages: PHP, ASP, Python. |
| Cannot access databases directly. | Can access and manage databases. |
| Output is visible to users. | Output is sent to the user after processing. |
| Less secure because code is visible. | More secure because code runs on the server. |
| Depends on the browser for execution. | Depends on the server for execution. |
हिन्दी में:
Client Side Scripting और Server Side Scripting दो प्रकार की वेब स्क्रिप्टिंग हैं जिनका उपयोग डायनेमिक वेब पेज बनाने के लिए किया जाता है। इन दोनों में मुख्य अंतर यह है कि कोड कहाँ चलता है — यूज़र के ब्राउज़र पर या सर्वर पर।
| Client Side Scripting | Server Side Scripting |
|---|---|
| कोड यूज़र के वेब ब्राउज़र में चलता है। | कोड वेब सर्वर पर चलता है। |
| यूज़र इंटरैक्शन और पेज डिज़ाइन के लिए उपयोग होता है। | डेटाबेस कनेक्शन और डेटा प्रोसेसिंग के लिए उपयोग होता है। |
| तेज़ चलता है क्योंकि सर्वर से अनुरोध नहीं भेजता। | थोड़ा धीमा होता है क्योंकि सर्वर से अनुरोध भेजना पड़ता है। |
| उदाहरण भाषाएँ: JavaScript, VBScript. | उदाहरण भाषाएँ: PHP, ASP, Python. |
| डेटाबेस को सीधे एक्सेस नहीं कर सकता। | डेटाबेस को एक्सेस और प्रबंधित कर सकता है। |
| आउटपुट यूज़र को दिखाई देता है। | आउटपुट प्रोसेस होने के बाद यूज़र को भेजा जाता है। |
| सुरक्षा कम होती है क्योंकि कोड दिखाई देता है। | अधिक सुरक्षित होता है क्योंकि कोड सर्वर पर चलता है। |
| निष्पादन के लिए ब्राउज़र पर निर्भर। | निष्पादन के लिए सर्वर पर निर्भर। |
Q. What is Variable? Write a JavaScript program to illustrate the variable.
In English:
A variable in JavaScript is a container that stores data or information which can be used and changed later in the program.
It is like a box that holds a value (such as number, text, etc.).
👉 In simple words:
A variable is used to store data temporarily in memory.
Syntax:
var variableName = value;
let variableName = value;
const variableName = value;
Example Program:
// JavaScript program to illustrate variables
var name = "Gopal"; // String variable
let age = 20; // Number variable
const country = "India"; // Constant variable
document.write("Name: " + name + "<br>");
document.write("Age: " + age + "<br>");
document.write("Country: " + country);
Output:
Name: Gopal
Age: 20
Country: India
हिन्दी में:
Variable JavaScript में एक कंटेनर (Container) होता है जो डेटा या जानकारी को स्टोर (संग्रह) करता है।
इसे ऐसे समझो जैसे एक डिब्बा (box) जिसमें कोई भी मान (value) रखी जाती है।
👉 सरल शब्दों में:
Variable का उपयोग अस्थायी रूप से डेटा को मेमोरी में रखने के लिए किया जाता है।
Syntax (वाक्य रचना):
var variableName = value;
let variableName = value;
const variableName = value;
उदाहरण प्रोग्राम:
// Variable को दर्शाने वाला JavaScript प्रोग्राम
var name = "Gopal"; // स्ट्रिंग प्रकार का वेरिएबल
let age = 20; // नंबर प्रकार का वेरिएबल
const country = "India"; // स्थिर वेरिएबल (Constant)
document.write("Name: " + name + "<br>");
document.write("Age: " + age + "<br>");
document.write("Country: " + country);
आउटपुट:
Name: Gopal
Age: 20
Country: India
Q. What is Data Type in JavaScript?
In English:
A data type in JavaScript defines the kind of value a variable can hold.
It tells the computer what type of data is being stored — for example, number, text, true/false, etc.
👉 In simple words:
Data types tell JavaScript what kind of value is stored in a variable.
Types of Data Types in JavaScript:
| Type | Description | Example |
|---|---|---|
| 1. String | Text values written in quotes | "Hello", 'Gopal' |
| 2. Number | Numeric values (with or without decimal) | 10, 5.5 |
| 3. Boolean | True or False values | true, false |
| 4. Undefined | When a variable is declared but no value is assigned | var x; |
| 5. Null | Represents an empty or no value | var x = null; |
| 6. Object | Collection of data in key-value pairs | {name: "Gopal", age: 20} |
| 7. Array | Used to store multiple values in one variable | [1, 2, 3, 4] |
Example Program:
var name = "Gopal"; // String
var age = 20; // Number
var isStudent = true; // Boolean
var address; // Undefined
var marks = null; // Null
document.write(typeof name + "<br>");
document.write(typeof age + "<br>");
document.write(typeof isStudent + "<br>");
document.write(typeof address + "<br>");
document.write(typeof marks);
Output:
string
number
boolean
undefined
object
हिन्दी में:
Data Type JavaScript में यह बताता है कि कोई variable किस प्रकार का मान (value) रखता है।
यह कंप्यूटर को बताता है कि डेटा संख्या है, टेक्स्ट है या कोई और प्रकार का है।
👉 सरल शब्दों में:
Data Type यह बताता है कि वेरिएबल में किस तरह का डेटा रखा गया है।
JavaScript के मुख्य Data Types:
| प्रकार (Type) | विवरण (Description) | उदाहरण (Example) |
|---|---|---|
| 1. String | टेक्स्ट के लिए उपयोग किया जाता है | "Hello", 'Gopal' |
| 2. Number | संख्यात्मक मान (नंबर) | 10, 5.5 |
| 3. Boolean | True या False मान | true, false |
| 4. Undefined | जब वेरिएबल घोषित हो लेकिन मान न दिया जाए | var x; |
| 5. Null | खाली या कोई मान नहीं | var x = null; |
| 6. Object | डेटा को key-value रूप में संग्रहित करता है | {name: "Gopal", age: 20} |
| 7. Array | एक वेरिएबल में कई मान रखता है | [1, 2, 3, 4] |
Example Program (उदाहरण प्रोग्राम):
var name = "Gopal"; // स्ट्रिंग
var age = 20; // नंबर
var isStudent = true; // बूलियन
var address; // अनडिफाइंड
var marks = null; // नल
document.write(typeof name + "<br>");
document.write(typeof age + "<br>");
document.write(typeof isStudent + "<br>");
document.write(typeof address + "<br>");
document.write(typeof marks);
आउटपुट:
string
number
boolean
undefined
object
Q. What is Conditional Operator in JavaScript?
In English:
A conditional operator in JavaScript is also called the ternary operator because it uses three operands.
It is used to check a condition and return one value if the condition is true and another value if it is false.
👉 It is a short form of if-else statement.
Syntax:
condition ? value_if_true : value_if_false;
Example:
var age = 18;
var result = (age >= 18) ? "Eligible to Vote" : "Not Eligible";
document.write(result);
Output:
Eligible to Vote
Explanation:
- If the condition
(age >= 18)is true, it prints “Eligible to Vote”. - Otherwise, it prints “Not Eligible”.
In Hindi (हिन्दी में):
Conditional Operator को JavaScript में Ternary Operator भी कहा जाता है क्योंकि इसमें तीन भाग होते हैं।
यह किसी शर्त (condition) की जाँच करता है और सही होने पर एक मान तथा गलत होने पर दूसरा मान लौटाता है।
👉 इसे if-else statement का छोटा रूप कहा जा सकता है।
Syntax (संरचना):
condition ? value_if_true : value_if_false;
Example (उदाहरण):
var age = 18;
var result = (age >= 18) ? "Vote करने योग्य" : "Vote करने योग्य नहीं";
document.write(result);
Output:
Vote करने योग्य
Explanation (व्याख्या):
- अगर
(age >= 18)सही है, तो यह “Vote करने योग्य” दिखाएगा। - अगर यह गलत है, तो यह “Vote करने योग्य नहीं” दिखाएगा।
👉 Memory Trick:
Ternary = 3 parts → Condition ? True : False
(Think: “If true do this, else do that.”)
