0% found this document useful (0 votes)
11 views

JavaScript

Uploaded by

feveripl98
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

JavaScript

Uploaded by

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

JavaScript

 The script which is running within the browser is called as Client Side
Script.
 Ex:- JavaScript, AngularJS, Vue JS.
Introduction->
 JavaScript is the scripting language of HTML and the web.
 JavaScript is a client side scripting language.
 JavaScript is a dynamic, untyped language.
 JavaScript is interpreted language.
 JavaScript is case sensitive language.
Creation of JavaScript->
 Created in May 1995.
 JavaScript is created by Netscape Corporation.
 Brendan Eich is the Inventor of JavaScript.
Features of JavaScript->
 JS provide client side validation.
 JS is simple.
 DOM traversing.
 DOM manipulation.
 Event Handling.
 Fast Execution.
 Cross Browser Support.
S/W Requirements for JavaScript->
 Web Browser->Any
 Text Editor->Notepad
JavaScript
 JavaScript is a Scripting language for web.
 JavaScript is used in millions of web pages to improve their
functionality, validate forms and much more.
 JavaScript is the most popular Scripting language on the Internet and
works on all major browser’s such as Internet Explorer, chrome ,
Mozilla Firefox, etc.

What JavaScript Can do?


 JavaScript can add multiple Functionality on a single click.
 You can add client side validation through JavaScript.
 JavaScript can put dynamic text into an HTML page.
 JavaScript can react to events.
 JavaScript can be used to validate data.
Where to use JavaScript Tag?
JavaScript in <head>
<html>
<head>
<script>
Function demo1()
{
getElementById(‘tech’).innerHTML=’Technology’
}
</script>
</head>
<body>
<p id=”tech”>Techpile</p1>
<button type=”button” onclick=”demo1”>Change Text</button>
</body>
</HTML>
Variable->
 Variable are “Containers” for storing information.
 JavaScript variable are used to hold values or expression.
 A variable can have short name ,like x or more descriptive name like
carname.
Rules for JavaScript variable names->
 Variable name are case sensitive.
 Variable name must begin with letter or the underscore character.
Declaration of JavaScript Variable->
 You can declare variable with var statement.
 var x=document.getElementById(“demo”)
 x.innerHTML=”Tech”
Variable in JavaScript:-
 Variable i JavaScript are used to store data that can be used and
manipulate.
 Throughout your code, there are many ways to declare variable like :
var, let and const. Each has different rules regarding their scope.
 var:
 Scope: var is function-scoped, meaning it is limited to the function in
which it’s declared. If declared outside function it becomes globally
scoped.
 Reassignability: Variable declared with var can be reassigned . You
can change their value many times.
 Example:
var name, a, b;
let d, e;
name="Technology";
a="Anay"
b="Shukla"
d=100;
e=200;
console.log(a+ b);
console.log(d+ e);
console.log(name);
 Let:
 Scope: let is block-scoped, which means its limited to the block
statement , or expression where it’s declared. A block typically defined
by curly braces{}.
 Reassignability: variable declared with let can be reassigned , similar to
var.
 Example:
let age=25;
if(true);
{
let age=30;
console.log(age);
}
console.log(age);
 Const:
 Scope: Like let const is also block-scoped.
 Reassignability: const is used for variable that should not be
reassigned after their initial assignment . Once you assign a value
to const variable, you cannot change it.
 Note-> If a const variable holds an object or array , you can still
modify the content of the object or array. However, you cannot
reassign the variable to completely new object or array.
 Example:
const person={Name:"Techpile"};
person.name='bob';
console.log(person.name);
const pi=3.14;
pi=3.145 //Error

Naming Conventions->
When naming a variable, it’s important to follow some common
naming conventions to make your code mode readable and
maintainable.
1. Camel Case->
In camelCase, the first word is lower case , and each subsequent
word start with uppercase letter. This is the most common
convention in JavaScript for variable and function name.
Example:- techpileTechnology, firstName, totalAmount, userAge
2. Snake Case->
In snake_case , all words are lowercase and separated. This is
less common in JavaScript but sometimes used for constants and
global variable.
Example:- first_name, total_amount, user_age

Comments In JavaScript->
1. Single Line Comment:-
//content
2. Multi-line Comment:-
/*content*/

Data Types In JavaScript->


In JavaScript ,datatype represent the different kinds of values
that can be stored and manipulated in a program. They are broadly
divided into primitive types and references type.
1. Primitive Type:-
Primitive Data types are the most basic types in JavaScript. They
represent single values and are immutable, means their actual
values cannot changed once created.
i) string: -
 Represents text or sequence of characters.
 Synatx:-
 string are enclosed in single (‘’),double(“”) and backricks quotes.
 Example:
let name=”Techpile”
ii) number:-
 Represent both integers and floating numbers.
 Syntax:-
 Numbers are written without quotes.
 Example:-
 let age=4.5

iii) Boolean:-
 Represent logical values ,either true or false.
 Example:-
 let isActive =true;
let hasFinished =false;
iv) null:-
 Represent a intentional absence of any object value. It’s often
used to signify that a variable should be empty or have no
value.
 Example:-
 let car=null //means car has no value.

You might also like