What is JavaScript? Notes by home academy

 

What is JavaScript?

  • JavaScript is a lightweight, interpreted scripting language used to make webpages interactive.

  • Created by Brendan Eich in 1995.

  • It runs in the browser (client-side) but can also run on servers (Node.js).


📌 Key Features of JavaScript

FeatureDescription
Client-SideRuns in the user's browser
InterpretedNo need to compile
Dynamic TypingNo need to declare variable type
Object-BasedUses objects for structure
Event-DrivenResponds to user actions (click, type)
Cross-PlatformWorks on all browsers

🧱 Basic Syntax

javascript
<script> alert("Hello, JavaScript!"); </script>

JavaScript is embedded within an HTML file using the <script> tag.


📚 Basic Concepts with Examples

1. Variables

javascript
var x = 10; // old way let y = 20; // block scoped const z = 30; // constant

2. Data Types

javascript
let name = "Ali"; // String let age = 25; // Number let isAdult = true; // Boolean let user = null; // Null let temp; // Undefined

3. Operators

javascript
+ - * / % // Arithmetic == === != !== // Comparison && || ! // Logical

🔁 Control Structures

If-else

javascript
if (age > 18) { console.log("Adult"); } else { console.log("Minor"); }

Switch

javascript
switch(day) { case 1: alert("Monday"); break; default: alert("Other"); }

Loops

javascript
for (let i = 0; i < 5; i++) { console.log(i); } let i = 0; while (i < 5) { console.log(i); i++; }

🔤 Functions in JavaScript

javascript
function greet(name) { return "Hello " + name; } console.log(greet("Afzal"));

Arrow Function:

javascript
const greet = (name) => "Hi " + name;

🎯 Events in JavaScript

EventDescription
onclickWhen element is clicked
onchangeValue changed
onloadWhen page loads
onmouseoverMouse over element

Example:

html
<button onclick="alert('Clicked!')">Click Me</button>

📦 JavaScript and DOM (Document Object Model)

DOM allows JavaScript to interact with HTML elements.

html
<p id="demo">Hello</p> <script> document.getElementById("demo").innerHTML = "Changed Text"; </script>

⚙️ Arrays and Objects

Arrays

javascript
let fruits = ["Apple", "Banana", "Mango"]; console.log(fruits[1]); // Banana

Objects

javascript
let person = { name: "Ali", age: 25, city: "Srinagar" }; console.log(person.name); // Ali

📐 Useful JavaScript Methods

MethodUse
alert()Show popup message
console.log()Print to browser console
prompt()Input box popup
parseInt()Convert to integer
toString()Convert to string

🌍 Practical Applications of JavaScript

AreaExamples
Web InteractivityClick, hover, drag/drop
Form ValidationCheck required fields
AnimationsInteractive sliders, menus
Web APIsGoogle Maps, YouTube APIs
Server-side (Node.js)Real-time apps, chatbots

Frequently Asked MCQs

  1. Who developed JavaScript?
    a) Dennis Ritchie
    b) Bjarne Stroustrup
    c) Brendan Eich ✅
    d) Tim Berners-Lee

  2. Which tag is used to write JavaScript in HTML?
    a) <js>
    b) <javascript>
    c) <script>
    d) <code>

  3. Which is NOT a JavaScript data type?
    a) String
    b) Number
    c) Float ✅ (JS has only Number type)
    d) Boolean

  4. Which method displays a message in a popup box?
    a) print()
    b) popup()
    c) alert()
    d) show()

  5. What is the result of 2 + "2" in JavaScript?
    a) 4
    b) 22 ✅ (String concatenation)
    c) NaN
    d) Error


🧠 Important Points for Exams

  • JavaScript is case-sensitive

  • == checks value only, === checks value + type

  • Can be used for both client-side and server-side

  • Commonly used with HTML + CSS

  • JavaScript files use .js extension


📝 Conclusion

JavaScript makes websites dynamic and interactive. It's essential for frontend development, and with Node.js, for backend as well.

homeacademy

Home academy is JK's First e-learning platform started by Er. Afzal Malik For Competitive examination and Academics K12. We have true desire to serve to society by way of making educational content easy . We are expertise in STEM We conduct workshops in schools Deals with Science Engineering Projects . We also Write Thesis for your Research Work in Physics Chemistry Biology Mechanical engineering Robotics Nanotechnology Material Science Industrial Engineering Spectroscopy Automotive technology ,We write Content For Coaching Centers also infohomeacademy786@gmail.com

Post a Comment (0)
Previous Post Next Post