0% found this document useful (0 votes)
3 views5 pages

intro javascript

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
3 views5 pages

intro javascript

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 5

What is JavaScript:

JavaScript is a dynamically typed language javascript it is a premier client-side scripting


language used on the web alongwith HTML.
It is created by Brendan Eich in 1995 while working at Netscape Communication.
JavaScript is an object-oriented programming (OOP) language, but it is prototype-based, not
class-based like traditional OOP languages such as Java or C++. JavaScript supports the
principles of object-oriented programming, such as encapsulation, inheritance, and
polymorphism, but it implements them in its unique way.

Variables:
A variable in programming is a container for storing data values. It acts as a symbolic name
(or identifier) that represents a value in a program, allowing you to use and manipulate the
data more efficiently. Variables make your code dynamic and reusable by enabling changes
to stored values.

Key Characteristics of Variables

1. Name: The identifier you use to reference the variable.


2. Value: The data or information stored in the variable.
3. Data Type: The kind of data the variable holds, such as numbers, strings, or objects.

value

let num = 123; Data Type =


number,

name

Variables Rules:-
1. Variables Names Are Case Sensitive “a” & “A” is different
2. Only Letters, Digits, Underscore(_,-) and $ this are allowed [Not Even A Space]
3. Only a Letter , Underscore(_) or $ should be 1st Character while variable declaration
4. Reserved words cannot be variable name eg: console, function etc

Naming Convention for Variables:-


fullName Camel case
full_name Snake case
full-name Kebab case
FullName Pascal case
In JavaScript, let, const, and var are keywords used to declare variables.
var = variable can be re-declared and updated. A global scope variable
let = Variable cannot be re-declared but can be updated. A block scope variable
const = variable cannot be re-declared or updated. A block scope variable.

1. Global Scope
Definition:
 A variable or function is said to have a global scope if it is declared outside of any
function, block, or module.
 Global variables can be accessed and modified anywhere in the program.

2. Block Scope
Definition:
 A variable has block scope if it is declared inside a block (enclosed by {}) using let
or const.
 The variable is accessible only within that block and its nested blocks.

There are two major Category of Datatypes:


Primitive Type
 Number = 123
 String= “abcd”, “abcd123”
 Boolean = True
 Undefined = let a; Variable is declared but not initialized
 Null = let b = null; Explicitly assigning null and absence of a value.
 BigInt = output will be 123n
 Symbol = let b = Symbol("hello!") output will be Symbol(hello!)
Composite Type
 Object =An object is a collection of key-value pairs where the keys are called
properties
Example :-
const student={
name: "rabnawaz",
rollNo: 12,
dept: "BscIT",
}
 Arrays = Store ordered data
Example:-
let fruits = ["Apple", "Banana", "Cherry"];

 Functions = Perform reusable actions, When developing an application, you often


need to perform the same action in many places. For example, you may want to show
a message whenever an error occurs.
To declare a function, you use the function keyword, followed by the function name, a list
of parameters, and the function body as follows:
Syntax:-
function functionName(parameters) {
// function body// ...
}
Parameters vs. Arguments
The terms parameters and arguments are often used interchangeably. However, they are
essentially different.
When declaring a function, you specify the parameters. However, when calling a
function, you pass the arguments that are corresponding to the parameters.
For example, in the say() function, the message is the parameter and the 'Hello' string is
an argument that corresponds to the message parameter.
function say(message) {
console.log(message);
}

let result = say('Hello');


console.log('Result:', result);

Example:-
function add(a, b) {
return a + b;
}
let sum = add(5, 3); // Call the function
console.log(sum);

What is Document Object Model (DOM):


The Document Object Model (DOM) is an application programming interface (API) for
manipulating HTML documents.
The DOM represents an HTML document as a tree of nodes. The DOM provides functions
that allow you to add, remove, and modify parts of the document effectively.
Note that the DOM is cross-platform and language-independent way of manipulating HTML
and documents (tags).
Example :-
<html>
<head>
<title>JavaScript getElementById() Method</title>
</head>
<body>
<p id="message">A paragraph</p>
</body>
</html>
const some = document.getElementById('message');
console.log(some);

What is the Window Object in JavaScript?


The window object is the global object in client-side JavaScript. It represents the browser's
window or tab where the script is running and provides methods, properties, and events that
allow you to interact with the browser and manipulate the DOM (Document Object Model).
Every JavaScript object, variable, or function declared globally automatically becomes a
property of the window object.

Flow Structure for How the JavaScript manipulates the html tags for website creation.

Windows(browser)
Document Object Model

HTML

head body

Simple Hello world Javascript Program


Step 1:- create a HTML file
Step 2:- Create a javascript file
Let output = “Hello World!!”;
Console.log(output);
Step 3:- Link both file by using <script src=”javascript file name”></script>
Step 4:- Run a HTML file and right click tab open inscpect option or press f12 and see output

You might also like