0% found this document useful (0 votes)
4 views25 pages

Presentation Js

JavaScript is a dynamically typed scripting language used for creating interactive webpages, performing form validations, and providing functionality. It includes various ways to integrate with HTML, such as using the head or body tags and external scripts, and operates through a JS engine that interprets and compiles code. Key concepts include variable declarations (var, let, const), scopes, hoisting, and different types of functions, including named, anonymous, IIFE, and arrow functions.

Uploaded by

k4998559
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views25 pages

Presentation Js

JavaScript is a dynamically typed scripting language used for creating interactive webpages, performing form validations, and providing functionality. It includes various ways to integrate with HTML, such as using the head or body tags and external scripts, and operates through a JS engine that interprets and compiles code. Key concepts include variable declarations (var, let, const), scopes, hoisting, and different types of functions, including named, anonymous, IIFE, and arrow functions.

Uploaded by

k4998559
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 25

What is

Javascript ?
Javascript is a scripting and
dynamically typed language.
Creates interactive
webpages.
USES
• Performs form validations
•Displays pop-up windows
•Provides Functionality
•Dynamic webpages
Ways to use javascript in HTML

1. Javascript in head tag


2. Javascript in body tag
3. External javascript
Syntax:
<script src="./script.js"></script>
JS Engine
The interpreter goes through the source code and interprets it line by
line, executing each line as it encounters it.
•Js engine converts the code written into machine code.
• Google follows v8 engine(program)
Javascript Parser
code (knows
syntax and AST
original code
rules)

Compiler Interpreter
machinecod (byte
e code)

JS ENGINE WORKING
Parser:(Syntax analyzer)
•It takes the javascript code and analyzes every
syntax , throws error if there is wrong syntax.
•This parser converts code into data structure.
AST
Stands for abstract syntax tree
•Provides graphical representation of the source
code.
•Abstract syntax trees are data structures due to their
property of representing the structure of program code.
Execution Context
It's an execution environment that helps code get
executed.
Consists of two phases:1.creation phase 2.Execution
phase
1.creation phase: sets memory to variables and
functions
2.Execution phase: assigns original values and
executes the code line by line.
Creation Phase
•It is a part of Execution context.
•It contains two components 1.memory 2.code
Variables in Javascript
Variables are containers which is used to store
different data types.
Javascript supports three types of variable
declarations,
1.var
2.let
3.const
1.VAR type
Declaration:
Var name;
Assignment:
name="javascript";
Initialization:
Var name="javascript";
•By using var keyword, variables can be accessed before
declaration and initialization.This has global scope.
• var keyword allows redeclaration and re-
assignment.
Syntax:
function print() {
var name;
console.log(name); #undefined
name = "JavaScript";
}
print();
Let keyword
Let is introduced in ECMAscript 2015.
•By using let keyword variables are not accessed before
declaration and initialization ,throws reference error
Syntax:
console.log(age);
let age = 5;
#ReferenceError: Cannot access 'age' before initialization
•let keyword does not allow re-declaration but allows re-
assignment #syntax error
Const keyword
•It is also introduced in ECMAscript 2015.
•Const keyword can't accessed before initialization
throws error.
•Re-declaration and re-assignment can't be done throws error.
Syntax:
const age=5;
console.log(age);
const age=10; #syntax error
Scope Types
Scope determines the accessebility of variables.
Js has three types of scopes
1.Block scope
2.Function scope
3.Global scope
1.Block scope
Block refers to the code that is written inside curly braces.
•Let and const are block scoped variables.
•Variables defined within block can't be accessed outside block.
Syntax:
{
let name="js";
const age=10;
console.log(name); #accessible
console.log(age); #accessible
}
console.log(name); # throws ref error
console.log(age); # throws error
2.Function scope
• Variables inside the function are accessible within the
function only.
•var keyword has function scope.
Syntax:
function scope(){
var name="scopes";
}
scope()
console.log(name); # throws ref error
3.Global scope
•Variables declared outside of any function or block have global scope.
•They are accessible from anywhere
Syntax:
var name="js";
let age=12;
const is=44;
function scopes(){
console.log(name);
console.log(age);
console.log(is);}
scopes()
Hoisting in JS
•Hoisting is JavaScript's default behavior of moving all declarations to
the top of the current scope .
•Hoisting works on variables declared with var keyword.
•For let and const keyword hoisting will not work.
Syntax:
console.log(number) # declaration hoisted at top
// undefined
console.log(name) # throws reference error
var number = 10
let name="js"
console.log(number) #10
Functions
•A function is a block of reusable code.
Terms:
1.Function Declaration: function keyword, function-
name,parameters.
2.Function calling:Function name, arguments.
Syntax:
function sum(num1, num2){
return num1 + num2;
}
sum(2,3);
Sum(4,5);
Types of functions
1.Named Functions
2.Anonymous function
3.Immediately invoked function expression.
4.Arrow function
Function expression:
Assigning function to a variable.
2.Anonymous Function
The function which does not contain function name
Ex: function(num1,num2){
Var res=num1+num2;
return res;
}
Sum=function(num1,num2)
3.IIFE
When we want to execute a function immediately
where they created.
Syntax:
(function definition)();
( function product(num1,num2){
Var res=num1 * num2
return res;
}) (6,8);
4.Arrow function
Arrow functions were inroduced in Es6.
Var function-name=(parameters)=>{
body
}
Syntax:
var product=(num1,num2)=>{return num1*num2}
product(5,6)
Operators
Performs operations based on operands.
Different types of operators in javascript:
•Arithmetic opeartors •Assignment operators
•Comparison operators •Logical operators
•Bitwise operators •Ternary operators

You might also like