JavaScript Basics
JavaScript Basics
Basics
• Where it runs:
• Browser (Client-side)
• Server (Node.js)
• Uses:
• Web interactivity
• Dynamic content
• Form validation
Why JavaScript?
Many of you may wonder why JavaScript is so popular among developers. The simple reason is
that JavaScript saves time!
With JavaScript, you can write both frontend and backend code.
•Frontend: Frameworks like React.js and Angular.js are used to build interactive user
interfaces.
•Backend: Tools like Node.js and Express.js allow you to build server-side applications.
By using the same language for both ends, development becomes faster and more efficient.
Connecting JavaScript to HTML?
HTML Boilerplate
To link JavaScript to your HTML, you use the <script>
tag.
• Data Types:
Assignment Operators =, +=, -=, *=, /=, %= , **= Assign values to variables x = 5, x += 3
==, ===, !=, !==, >, <, >=, Compare values and
Comparison Operators 5 == 5, x > 3
<= return boolean result
"Hello" + " World", str +=
String Operators +, += Concatenate strings
"!"
Logical Operators &&, ||, ! , !`
Perform bitwise
Bitwise Operators &, | , ^, ~, <<, >>`
operations
Conditional (if-else)
Ternary Operator ?: x > 5 ? "Yes" : "No"
operator
Determine the type of a typeof 42, obj instanceof
Type Operators typeof, instanceof
variable or object Object
Control Flow
•Arrow Functions
•A shorter syntax for functions:
Objects
• Objects are variables too. But objects can contain many values.
•Accessing Object
1.Dot Notation
2.Bracket Notation
Targeting HTML Elements in JavaScript
• In JavaScript, you can target HTML elements using DOM (Document Object Model)
methods. These methods allow you to interact with specific elements in the document, such as
elements with specific IDs, classes, or tags.
Example :
Thank You