SlideShare a Scribd company logo
1 of 53
Course Evaluation

 5 lectures and 5 labs

 Evaluation:
    60% Project and Assignments
    40% Labs and Quizzes
Lecture Outline

 Introduction

 JavaScript Syntax

 Built-in objects

 Functions
How did it all start?

 Invented by Brendan Eich at Netscape

 First appeared in Navigator 2.0 browser.

 Appeared since Microsoft Internet Explorer 3.0.
What JS isn‟t ?
What JavaScript isn‟t?

 It isn‟t Java

 It isn‟t HTML or a version of it

 It isn‟t compiled

 For Client-Side JS:
    It has no graphics capabilities, except for the powerful
     ability to dynamically generate HTML.
    It isn‟t allowed the reading or writing of files.
    It has no support for networking of any kind.
What JS is ?
What JavaScript is?
 It is a scripting language, to be processed and executed
  by a JavaScript interpreter.

 It is dynamic.

 It is Object Oriented or Object-based (controversial
  subject).
    "ECMAScript is an object-oriented programming language
     for performing computations and manipulating
     computational objects within a host environment." ECMA-
     262

 It is general purpose programming language.

 It is event-driven.
At the Beginning
Javascript Engines

 Brendan Eich first engine SpiderMonkey

 Google Chrome  V8

 Safari  Nitro JavaScript engine

 Opera  Carakan

 IE 9+  Chakra

 Adobe Labs for ActionScript  Tamarin
Uses of Client-Side
          Javascript
 Form Validation

 Dynamic, and Highly Responsive content.

 Personalized Interface
Where is JavaScript
            added?
 In HTML file
    Between <script> tags
    Can be added to <head> section
       Mostly used to define functions
    Can be added inside <body> section

 In External file
    File will have only JavaScript Code, with extension .js
    In HTML file refer to this file using src attribute of
     <script> tag
Where is JavaScript
              added?
     Inside HTML file                 In external .js file

<!DOCTYPE html>                   <!DOCTYPE html>
<html>                            <html>
<head>
                                  <head>
<script type="text/javascript">
JavaScript goes here...           <script type="text/javascript"
</script>                         src="file.js">
</head>                           </script>
<body>                            </head>
Mark-up goes here...              <body>
<script type="text/javascript">
JavaScript goes here...
                                  Mark-up goes here...
</script>                         </body>
</body>                           </html>
</html>
JavaScript Syntax

 Statements

 Variables

 Dialogues and Alerts

 Data Types

 Operators

 Control Statements
Statements

 JS is case-sensitive.

 Statements are places in separate lines or
  separated by semi-colons on the same line.

 Comments are C/C++ like
    Single line //
    Multiple line /*………..*/
Variables

 Variable names follow C/C++ guidelines

 Variables are declared by „var‟ keyword

 A variable can be used direclty without declaring but
  it is not good practice.
Try variables and dialogues
        Use Developer tools
Dialogues and Alerts

 There are 3 types of dialogues
    alert()
       Show a message box with one button, has no return.
    confirm()
       Show a message box with 2 buttons (OK and Cancel).
       Returns true  OK pressed.
       Returns false Cancel pressed.
    prompt()
       Show a message box with 2 buttons (OK and Cancel) and
        a textbox
       Returns the text in textbox OK pressed
       Returns null  Cancel pressed
Data Types
 Primitive Types:
      Number: float or int
      String: any charaters enclosed in “…” or „….‟
      Boolean: true/false
      Undefined
      Null

 Object:
    any value not a primitive is an object.

 JavaScript is un-typed language, thus a variable can
  change it‟s type multiple times.
Useful built-in functions

 isNaN(input ) true/false
 isFinite()  true if finite number, false if not a number or
  Infinity
 parseInt( input, radix=10)  NaN if failed, or number if
  successful
 parseFloat(input) a floating point number or NaN
 eval(input)  tries to evaluate the input string as a
  javascipt code.
Operators

 Arithmetic Operators

 Logical Operators

 Bitwise Operators (self-study)

 Comparison Operators
Arithmetic Operator

Operator            Operation
+                   Addition or concatenation of strings
-                   Subtraction
*                   Multiplication
/                   Division
%                   Modulo, reminder of a division
++                  Increment (post or pre)
--                  Decrement (post or pre)
=                   Assignment
+=, -=,*=,/=, %=    Compound operators
Logical Operators

Operator           Operation
!                  Logical NOT
&&                 Logical AND
||                 Logical OR
Comparison Operators

Operator          Operation
==                Equality
===               Equality and type comparison
!=                Not Equal
!==               Not equal with type comparison
>, >=             greater than and greater than or
                  equal
<, <=             Less than and less than or equal
Operator Precedence

 From lowest to highest
   1.   Assignment operators (=, +=, -=, *=, /=, %=)
   2.   Conditional (?:)
   3.   Logical or (||)
   4.   Logical and (&&)
   5.   Equality (==, !=)
   6.   Relational (<, <=, >=, >)
   7.   Addition/Subtraction (+, -)
   8.   Multiply/divide/modulus (*, /, %)
   9.   Parentheses(())
Try operators and built –in
 functions on JS console
        Use Developer tools
Control Statements
1.     Conditional Statements       2.            Loop Statements
     a) if….else                              a) for
      if (some condition is true)
                                     for ( var i=0 ;i<10;i++)
       {
                                     {
           do something;
                                        document.write(“this is number” + i)
         }
                                     }
      else
       {                                      b) while
           do something else;
       }                                 while (condition)
                                         {
     b) switch / case                    statements
                                         }
     switch (expression)
     {                                        c) do…while
     case label1:
                statements               do
                [break]                  {
     default :                              statements
     }                                   }while(condition)
Built-in Objects

 String

 Date

 Math

 Array
String Object

 Properties:
  Property Name     Description
  length            The number of characters in the string.
String Object (Cont‟d)

 Methods :   Method Name                    Description
              charAt(n )                     Return the character at a given position

              indexOf( substr,[start])       Searches for first occurrence for a
                                             substring.
              lastIndexOf( substr,[start])   Searches for last occurrence for a
                                             substring.
              toString( )                    Returns the primitive string value.

              toUpperCase( )                 Returns with all characters converted to
                                             uppercase.
              substr(start, length)          Extracts a substring of a string.

              substring(from, to)            Extracts a substring of a string.

              slice(start , end)             Extracts a substring of a string. What‟s
                                             the difference then ??
              split(delimiter, limit)        Return array of strings, from splitting
                                             string into substrings at the
                                             boundaries specified by delimiter.
Date Object

 Object to manipulate date and time based on the
  local machine time.

 Examples:
    var d=new Date() //returns date of local machine now
    var d = new Date(2008, 1, 1); //1/2/2008
    d.setFullYear(d.getFullYear( ) + 1);
   //return 1/2/2009
    var weekday = d.getDay( ); //0  Sunday
Math Object

 Math is a built-in global object, which provides a
  number of methods and properties that are useful for
  mathematical operations, but can‟t be instantiated.

 Constant Properties:

     Constants             value
     Math.PI               3.141592653589793
     Math.E                2.718281828459045
     Math.LN2              0.6931471805599453
Math Objects

 Methods
    Methods
    Math.abs()       Returns the absolute unsigned value
    Math.ceil()      Return rounded number up to nearest interger
    Math.cos()       Returns cosine of number
    Math.floor()     Returns number down to nearest integer
    Math.pow()       Returns the number raised to a power
    Math.random()    Returns a number between 0 and 1.0
    Math.sqrt()      Returns square root of number
    Math.round()     Returns number rounded to closest integer
Arrays
 A datatype(object) that contains a number of other
  datatypes (primitive or objects).
 An array is a data store, contains indexed elements
  (index start @ 0)
 Declaring an array
    var myarr=[]; //declaring an array literal
    var myarr=[1 , 2 , ‘three’,’four’,false];
    var myarr= new Array() //using array constructor.
    Var myarr=new Array(2) //an array with 2 undefined
     elements
    var myarr=new Array(1,2,’r’,true); //an array with 4
     elements
Arrays (Cont‟d)
 Retrieving an element
    use the index in square brackets
         myarr[0]
 Deleting an element
    Delete myarr[2]
Array Properties

Property           Description
Length             Return number of elements of array
Array Methods

Method       Description
concat()     Concatenates elements from one array to another array.
join()       Joins the elements of an array by a separator to form a
             string.
pop()        Removes and returns the last element of an array.
push()       Adds elements to the end of an array.
reverse()    Reverses the order of the elements in an array.
shift()      Removes and returns the first element of an array.
slice()      Creates a new array from elements of an existing array.
sort()       Sorts an array alphabetically or numerically.
splice()     Removes and/or replaces elements of an array.
toString()   Returns a string representation of the array.
unshift()    Adds elements to the beginning of an array.
Associative Arrays
             (HASH)
 Arrays with index of elements a string instead of number.

 All objects are Associative arrays

 Example:
      var ar=[]; //create an array instance
      ar[„name‟]=„John Smith‟;
      ar[„age‟]=22;
      var x=ar[„name‟] or x=ar.name;
For/in loop

 Special type of for loop
 To loop over elements of an array, or properties of an
  object/associative array.
 Example:
var a = ['a', 'b', 'c', 'x', 'y', 'z'];
var result = 'n';
for (var i in a)
{
     result += 'index: ' + i + ', value: '
                              + a[i] + 'n’;
}
alert(result);
Functions

 Functions are objects, can be returned from another functions.

 Functions are first-class citizens.

 Functions used for code reuse, information hiding, and
  composition.

 Example:
        function square(x)
        {
                  return (x*x)
        }

 To call it:
        var x=square(4)     x=16
Functions (Cont‟d)
 Anonymous functions is a function without name

 Example:
       var f=function(a,b){return a+b}

 To call it,
       var x=f(1,2)  x=3;

 Self-invoked function:
    are anonymous functions invoked just after it declaration.
    To self-invoke an anonymous function add () to the end of its
     definition

 Example:
       var x=(function(a,b){return a+b})(1,2)  x=3
Functions (Cont‟d)

 Callback functions:
    Functions sent to other functions.
    Example:
      function invoke_and_add(a, b)
      {
              return a() + b();
      }
      function one() {return 1;}
      function two() {return 2;}
      invoke_and_add(one, two);
      invoke_and_add(function(){return 1;}, function(){return 2;})
Functions and Variable
            Scope
 There is No Block Scope, all variables declared in a
  function, no matter where, are defined throughout
  the function.

 Variables defined in function using „var‟ (where-
  ever) are local variables, if „var‟ is omitted they
  become global variables.
What is the output of the
         execution?
function f1(x,y)
     {
        if(x>3)
        {
            var z=3;
        }
        else
        {
            var zz=3;
        }
        alert(z+" - "+zz)
        zzz=300;
     }
     f1(1,3);
     alert(zzz);
What is the output of the
      execution now?
function f1(x,y)
     {
        if(x>3)
        {
            var z=3;
        }
        else
        {
            var zz=3;
        }
        alert(z+" - "+zz)
        zzz=300;
     }
     //f1(1,3);
     alert(zzz);
What is the output ?

var scope = "global";
function f( )
{
       alert(scope);
       var scope = "local";
       alert(scope);
}
f( );
References
 http://www.ecma-international.org/publications/files/ECMA-
  ST/Ecma-262.pdf
 https://developer.mozilla.org/en-US/docs/JavaScript
 http://www.w3.org/TR/DOM-Level-3-Events/#event-flow
 http://w3techs.com/technologies/overview/javascript_library/all
 For Testing JS Compatibility:
    http://www.robertnyman.com/javascript/index.html

 Brendan Eich Blog: https://brendaneich.com/
 Useful resources:
    http://yuiblog.com/crockford/

More Related Content

What's hot

Xbase - Implementing Domain-Specific Languages for Java
Xbase - Implementing Domain-Specific Languages for JavaXbase - Implementing Domain-Specific Languages for Java
Xbase - Implementing Domain-Specific Languages for Javameysholdt
 
Chapter 9 - Characters and Strings
Chapter 9 - Characters and StringsChapter 9 - Characters and Strings
Chapter 9 - Characters and StringsEduardo Bergavera
 
Chapter 2 - Getting Started with Java
Chapter 2 - Getting Started with JavaChapter 2 - Getting Started with Java
Chapter 2 - Getting Started with JavaEduardo Bergavera
 
JavaScript Objects
JavaScript ObjectsJavaScript Objects
JavaScript ObjectsReem Alattas
 
Generic Programming in java
Generic Programming in javaGeneric Programming in java
Generic Programming in javaGarik Kalashyan
 
Java Persistence API
Java Persistence APIJava Persistence API
Java Persistence APIIlio Catallo
 
DIWE - Working with MySQL Databases
DIWE - Working with MySQL DatabasesDIWE - Working with MySQL Databases
DIWE - Working with MySQL DatabasesRasan Samarasinghe
 
Lab #2: Introduction to Javascript
Lab #2: Introduction to JavascriptLab #2: Introduction to Javascript
Lab #2: Introduction to JavascriptWalid Ashraf
 
Let's make a contract: the art of designing a Java API
Let's make a contract: the art of designing a Java APILet's make a contract: the art of designing a Java API
Let's make a contract: the art of designing a Java APIMario Fusco
 
Introduction to ad-3.4, an automatic differentiation library in Haskell
Introduction to ad-3.4, an automatic differentiation library in HaskellIntroduction to ad-3.4, an automatic differentiation library in Haskell
Introduction to ad-3.4, an automatic differentiation library in Haskellnebuta
 
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYAPYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYAMaulik Borsaniya
 
Clean code and Code Smells
Clean code and Code SmellsClean code and Code Smells
Clean code and Code SmellsMario Sangiorgio
 
Java tutorial for Beginners and Entry Level
Java tutorial for Beginners and Entry LevelJava tutorial for Beginners and Entry Level
Java tutorial for Beginners and Entry LevelRamrao Desai
 

What's hot (20)

Java Generics
Java GenericsJava Generics
Java Generics
 
Xbase - Implementing Domain-Specific Languages for Java
Xbase - Implementing Domain-Specific Languages for JavaXbase - Implementing Domain-Specific Languages for Java
Xbase - Implementing Domain-Specific Languages for Java
 
Chapter 9 - Characters and Strings
Chapter 9 - Characters and StringsChapter 9 - Characters and Strings
Chapter 9 - Characters and Strings
 
Chapter 2 - Getting Started with Java
Chapter 2 - Getting Started with JavaChapter 2 - Getting Started with Java
Chapter 2 - Getting Started with Java
 
JavaScript Objects
JavaScript ObjectsJavaScript Objects
JavaScript Objects
 
Generic Programming in java
Generic Programming in javaGeneric Programming in java
Generic Programming in java
 
Java Generics - by Example
Java Generics - by ExampleJava Generics - by Example
Java Generics - by Example
 
Clean coding-practices
Clean coding-practicesClean coding-practices
Clean coding-practices
 
Java Persistence API
Java Persistence APIJava Persistence API
Java Persistence API
 
Javascript
JavascriptJavascript
Javascript
 
DIWE - Working with MySQL Databases
DIWE - Working with MySQL DatabasesDIWE - Working with MySQL Databases
DIWE - Working with MySQL Databases
 
Java Performance MythBusters
Java Performance MythBustersJava Performance MythBusters
Java Performance MythBusters
 
Lab #2: Introduction to Javascript
Lab #2: Introduction to JavascriptLab #2: Introduction to Javascript
Lab #2: Introduction to Javascript
 
Let's make a contract: the art of designing a Java API
Let's make a contract: the art of designing a Java APILet's make a contract: the art of designing a Java API
Let's make a contract: the art of designing a Java API
 
Java q ref 2018
Java q ref 2018Java q ref 2018
Java q ref 2018
 
Introduction to ad-3.4, an automatic differentiation library in Haskell
Introduction to ad-3.4, an automatic differentiation library in HaskellIntroduction to ad-3.4, an automatic differentiation library in Haskell
Introduction to ad-3.4, an automatic differentiation library in Haskell
 
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYAPYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
 
Clean code and Code Smells
Clean code and Code SmellsClean code and Code Smells
Clean code and Code Smells
 
Lecture 7 arrays
Lecture   7 arraysLecture   7 arrays
Lecture 7 arrays
 
Java tutorial for Beginners and Entry Level
Java tutorial for Beginners and Entry LevelJava tutorial for Beginners and Entry Level
Java tutorial for Beginners and Entry Level
 

Similar to Introduction to Client-Side Javascript

Similar to Introduction to Client-Side Javascript (20)

JavaScript.pptx
JavaScript.pptxJavaScript.pptx
JavaScript.pptx
 
Javascript variables and datatypes
Javascript variables and datatypesJavascript variables and datatypes
Javascript variables and datatypes
 
Java tut1
Java tut1Java tut1
Java tut1
 
Tutorial java
Tutorial javaTutorial java
Tutorial java
 
Java Tut1
Java Tut1Java Tut1
Java Tut1
 
Java Tutorial
Java TutorialJava Tutorial
Java Tutorial
 
Java
JavaJava
Java
 
An Overview Of Python With Functional Programming
An Overview Of Python With Functional ProgrammingAn Overview Of Python With Functional Programming
An Overview Of Python With Functional Programming
 
Javascript
JavascriptJavascript
Javascript
 
JavaScript(Es5) Interview Questions & Answers
JavaScript(Es5)  Interview Questions & AnswersJavaScript(Es5)  Interview Questions & Answers
JavaScript(Es5) Interview Questions & Answers
 
Java Script ppt
Java Script pptJava Script ppt
Java Script ppt
 
Bw14
Bw14Bw14
Bw14
 
C++.pptx
C++.pptxC++.pptx
C++.pptx
 
Matlab Functions
Matlab FunctionsMatlab Functions
Matlab Functions
 
Ds lab handouts
Ds lab handoutsDs lab handouts
Ds lab handouts
 
Understanding linq
Understanding linqUnderstanding linq
Understanding linq
 
Ajax and JavaScript Bootcamp
Ajax and JavaScript BootcampAjax and JavaScript Bootcamp
Ajax and JavaScript Bootcamp
 
Java tutorials
Java tutorialsJava tutorials
Java tutorials
 
FP in Java - Project Lambda and beyond
FP in Java - Project Lambda and beyondFP in Java - Project Lambda and beyond
FP in Java - Project Lambda and beyond
 
NLJUG University Sessie: Java Reborn, Powered by Ordina
NLJUG University Sessie: Java Reborn, Powered by OrdinaNLJUG University Sessie: Java Reborn, Powered by Ordina
NLJUG University Sessie: Java Reborn, Powered by Ordina
 

More from Julie Iskander (20)

HTML 5
HTML 5HTML 5
HTML 5
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithms
 
C for Engineers
C for EngineersC for Engineers
C for Engineers
 
Design Pattern lecture 3
Design Pattern lecture 3Design Pattern lecture 3
Design Pattern lecture 3
 
Scriptaculous
ScriptaculousScriptaculous
Scriptaculous
 
Prototype Framework
Prototype FrameworkPrototype Framework
Prototype Framework
 
Design Pattern lecture 4
Design Pattern lecture 4Design Pattern lecture 4
Design Pattern lecture 4
 
Design Pattern lecture 2
Design Pattern lecture 2Design Pattern lecture 2
Design Pattern lecture 2
 
Design Pattern lecture 1
Design Pattern lecture 1Design Pattern lecture 1
Design Pattern lecture 1
 
Ajax and ASP.NET AJAX
Ajax and ASP.NET AJAXAjax and ASP.NET AJAX
Ajax and ASP.NET AJAX
 
jQuery
jQueryjQuery
jQuery
 
ASP.NET Lecture 5
ASP.NET Lecture 5ASP.NET Lecture 5
ASP.NET Lecture 5
 
ASP.NET lecture 8
ASP.NET lecture 8ASP.NET lecture 8
ASP.NET lecture 8
 
ASP.NET Lecture 7
ASP.NET Lecture 7ASP.NET Lecture 7
ASP.NET Lecture 7
 
ASP.NET Lecture 6
ASP.NET Lecture 6ASP.NET Lecture 6
ASP.NET Lecture 6
 
ASP.NET Lecture 4
ASP.NET Lecture 4ASP.NET Lecture 4
ASP.NET Lecture 4
 
ASP.NET Lecture 3
ASP.NET Lecture 3ASP.NET Lecture 3
ASP.NET Lecture 3
 
ASP.NET Lecture 2
ASP.NET Lecture 2ASP.NET Lecture 2
ASP.NET Lecture 2
 
ASP.NET Lecture 1
ASP.NET Lecture 1ASP.NET Lecture 1
ASP.NET Lecture 1
 
AJAX and JSON
AJAX and JSONAJAX and JSON
AJAX and JSON
 

Recently uploaded

Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 

Recently uploaded (20)

Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 

Introduction to Client-Side Javascript

  • 1.
  • 2. Course Evaluation  5 lectures and 5 labs  Evaluation:  60% Project and Assignments  40% Labs and Quizzes
  • 3. Lecture Outline  Introduction  JavaScript Syntax  Built-in objects  Functions
  • 4.
  • 5. How did it all start?  Invented by Brendan Eich at Netscape  First appeared in Navigator 2.0 browser.  Appeared since Microsoft Internet Explorer 3.0.
  • 7. What JavaScript isn‟t?  It isn‟t Java  It isn‟t HTML or a version of it  It isn‟t compiled  For Client-Side JS:  It has no graphics capabilities, except for the powerful ability to dynamically generate HTML.  It isn‟t allowed the reading or writing of files.  It has no support for networking of any kind.
  • 9. What JavaScript is?  It is a scripting language, to be processed and executed by a JavaScript interpreter.  It is dynamic.  It is Object Oriented or Object-based (controversial subject).  "ECMAScript is an object-oriented programming language for performing computations and manipulating computational objects within a host environment." ECMA- 262  It is general purpose programming language.  It is event-driven.
  • 11.
  • 12.
  • 13. Javascript Engines  Brendan Eich first engine SpiderMonkey  Google Chrome  V8  Safari  Nitro JavaScript engine  Opera  Carakan  IE 9+  Chakra  Adobe Labs for ActionScript  Tamarin
  • 14. Uses of Client-Side Javascript  Form Validation  Dynamic, and Highly Responsive content.  Personalized Interface
  • 15. Where is JavaScript added?  In HTML file  Between <script> tags  Can be added to <head> section  Mostly used to define functions  Can be added inside <body> section  In External file  File will have only JavaScript Code, with extension .js  In HTML file refer to this file using src attribute of <script> tag
  • 16. Where is JavaScript added? Inside HTML file In external .js file <!DOCTYPE html> <!DOCTYPE html> <html> <html> <head> <head> <script type="text/javascript"> JavaScript goes here... <script type="text/javascript" </script> src="file.js"> </head> </script> <body> </head> Mark-up goes here... <body> <script type="text/javascript"> JavaScript goes here... Mark-up goes here... </script> </body> </body> </html> </html>
  • 17.
  • 18. JavaScript Syntax  Statements  Variables  Dialogues and Alerts  Data Types  Operators  Control Statements
  • 19. Statements  JS is case-sensitive.  Statements are places in separate lines or separated by semi-colons on the same line.  Comments are C/C++ like  Single line //  Multiple line /*………..*/
  • 20. Variables  Variable names follow C/C++ guidelines  Variables are declared by „var‟ keyword  A variable can be used direclty without declaring but it is not good practice.
  • 21. Try variables and dialogues Use Developer tools
  • 22. Dialogues and Alerts  There are 3 types of dialogues  alert()  Show a message box with one button, has no return.  confirm()  Show a message box with 2 buttons (OK and Cancel).  Returns true  OK pressed.  Returns false Cancel pressed.  prompt()  Show a message box with 2 buttons (OK and Cancel) and a textbox  Returns the text in textbox OK pressed  Returns null  Cancel pressed
  • 23. Data Types  Primitive Types:  Number: float or int  String: any charaters enclosed in “…” or „….‟  Boolean: true/false  Undefined  Null  Object:  any value not a primitive is an object.  JavaScript is un-typed language, thus a variable can change it‟s type multiple times.
  • 24. Useful built-in functions  isNaN(input ) true/false  isFinite()  true if finite number, false if not a number or Infinity  parseInt( input, radix=10)  NaN if failed, or number if successful  parseFloat(input) a floating point number or NaN  eval(input)  tries to evaluate the input string as a javascipt code.
  • 25. Operators  Arithmetic Operators  Logical Operators  Bitwise Operators (self-study)  Comparison Operators
  • 26. Arithmetic Operator Operator Operation + Addition or concatenation of strings - Subtraction * Multiplication / Division % Modulo, reminder of a division ++ Increment (post or pre) -- Decrement (post or pre) = Assignment +=, -=,*=,/=, %= Compound operators
  • 27. Logical Operators Operator Operation ! Logical NOT && Logical AND || Logical OR
  • 28. Comparison Operators Operator Operation == Equality === Equality and type comparison != Not Equal !== Not equal with type comparison >, >= greater than and greater than or equal <, <= Less than and less than or equal
  • 29. Operator Precedence  From lowest to highest 1. Assignment operators (=, +=, -=, *=, /=, %=) 2. Conditional (?:) 3. Logical or (||) 4. Logical and (&&) 5. Equality (==, !=) 6. Relational (<, <=, >=, >) 7. Addition/Subtraction (+, -) 8. Multiply/divide/modulus (*, /, %) 9. Parentheses(())
  • 30. Try operators and built –in functions on JS console Use Developer tools
  • 31. Control Statements 1. Conditional Statements 2. Loop Statements a) if….else a) for if (some condition is true) for ( var i=0 ;i<10;i++) { { do something; document.write(“this is number” + i) } } else { b) while do something else; } while (condition) { b) switch / case statements } switch (expression) { c) do…while case label1: statements do [break] { default : statements } }while(condition)
  • 32.
  • 33. Built-in Objects  String  Date  Math  Array
  • 34. String Object  Properties: Property Name Description length The number of characters in the string.
  • 35. String Object (Cont‟d)  Methods : Method Name Description charAt(n ) Return the character at a given position indexOf( substr,[start]) Searches for first occurrence for a substring. lastIndexOf( substr,[start]) Searches for last occurrence for a substring. toString( ) Returns the primitive string value. toUpperCase( ) Returns with all characters converted to uppercase. substr(start, length) Extracts a substring of a string. substring(from, to) Extracts a substring of a string. slice(start , end) Extracts a substring of a string. What‟s the difference then ?? split(delimiter, limit) Return array of strings, from splitting string into substrings at the boundaries specified by delimiter.
  • 36. Date Object  Object to manipulate date and time based on the local machine time.  Examples:  var d=new Date() //returns date of local machine now  var d = new Date(2008, 1, 1); //1/2/2008  d.setFullYear(d.getFullYear( ) + 1); //return 1/2/2009  var weekday = d.getDay( ); //0  Sunday
  • 37. Math Object  Math is a built-in global object, which provides a number of methods and properties that are useful for mathematical operations, but can‟t be instantiated.  Constant Properties: Constants value Math.PI 3.141592653589793 Math.E 2.718281828459045 Math.LN2 0.6931471805599453
  • 38. Math Objects  Methods Methods Math.abs() Returns the absolute unsigned value Math.ceil() Return rounded number up to nearest interger Math.cos() Returns cosine of number Math.floor() Returns number down to nearest integer Math.pow() Returns the number raised to a power Math.random() Returns a number between 0 and 1.0 Math.sqrt() Returns square root of number Math.round() Returns number rounded to closest integer
  • 39. Arrays  A datatype(object) that contains a number of other datatypes (primitive or objects).  An array is a data store, contains indexed elements (index start @ 0)  Declaring an array  var myarr=[]; //declaring an array literal  var myarr=[1 , 2 , ‘three’,’four’,false];  var myarr= new Array() //using array constructor.  Var myarr=new Array(2) //an array with 2 undefined elements  var myarr=new Array(1,2,’r’,true); //an array with 4 elements
  • 40. Arrays (Cont‟d)  Retrieving an element  use the index in square brackets  myarr[0]  Deleting an element  Delete myarr[2]
  • 41. Array Properties Property Description Length Return number of elements of array
  • 42. Array Methods Method Description concat() Concatenates elements from one array to another array. join() Joins the elements of an array by a separator to form a string. pop() Removes and returns the last element of an array. push() Adds elements to the end of an array. reverse() Reverses the order of the elements in an array. shift() Removes and returns the first element of an array. slice() Creates a new array from elements of an existing array. sort() Sorts an array alphabetically or numerically. splice() Removes and/or replaces elements of an array. toString() Returns a string representation of the array. unshift() Adds elements to the beginning of an array.
  • 43. Associative Arrays (HASH)  Arrays with index of elements a string instead of number.  All objects are Associative arrays  Example:  var ar=[]; //create an array instance  ar[„name‟]=„John Smith‟;  ar[„age‟]=22;  var x=ar[„name‟] or x=ar.name;
  • 44. For/in loop  Special type of for loop  To loop over elements of an array, or properties of an object/associative array.  Example: var a = ['a', 'b', 'c', 'x', 'y', 'z']; var result = 'n'; for (var i in a) { result += 'index: ' + i + ', value: ' + a[i] + 'n’; } alert(result);
  • 45.
  • 46. Functions  Functions are objects, can be returned from another functions.  Functions are first-class citizens.  Functions used for code reuse, information hiding, and composition.  Example: function square(x) { return (x*x) }  To call it: var x=square(4)  x=16
  • 47. Functions (Cont‟d)  Anonymous functions is a function without name  Example: var f=function(a,b){return a+b}  To call it, var x=f(1,2)  x=3;  Self-invoked function:  are anonymous functions invoked just after it declaration.  To self-invoke an anonymous function add () to the end of its definition  Example: var x=(function(a,b){return a+b})(1,2)  x=3
  • 48. Functions (Cont‟d)  Callback functions:  Functions sent to other functions.  Example: function invoke_and_add(a, b) { return a() + b(); } function one() {return 1;} function two() {return 2;} invoke_and_add(one, two); invoke_and_add(function(){return 1;}, function(){return 2;})
  • 49. Functions and Variable Scope  There is No Block Scope, all variables declared in a function, no matter where, are defined throughout the function.  Variables defined in function using „var‟ (where- ever) are local variables, if „var‟ is omitted they become global variables.
  • 50. What is the output of the execution? function f1(x,y) { if(x>3) { var z=3; } else { var zz=3; } alert(z+" - "+zz) zzz=300; } f1(1,3); alert(zzz);
  • 51. What is the output of the execution now? function f1(x,y) { if(x>3) { var z=3; } else { var zz=3; } alert(z+" - "+zz) zzz=300; } //f1(1,3); alert(zzz);
  • 52. What is the output ? var scope = "global"; function f( ) { alert(scope); var scope = "local"; alert(scope); } f( );
  • 53. References  http://www.ecma-international.org/publications/files/ECMA- ST/Ecma-262.pdf  https://developer.mozilla.org/en-US/docs/JavaScript  http://www.w3.org/TR/DOM-Level-3-Events/#event-flow  http://w3techs.com/technologies/overview/javascript_library/all  For Testing JS Compatibility:  http://www.robertnyman.com/javascript/index.html  Brendan Eich Blog: https://brendaneich.com/  Useful resources:  http://yuiblog.com/crockford/

Editor's Notes

  1. From ECMA Specification
  2. External JS files makes better code reuse, and they’re cached in the browser instead of being downloaded with each page.
  3. It is good programming practice to place a semicolon at the end of every statement.
  4. To know datatype of a variable or value use typeof operatorSpecial values: InfinityNaNFalse is empty string, null, undefined, 0, NaN, false
  5. break  breaks a loopcontinue  break current iteration and jump to next.
  6. See methods and properties from notes of lecture or http://www.w3schools.com/jsref/jsref_obj_math.asp
  7. There are more constants defines, you can find them in notes or
  8. There are more constants defines, you can find them in notes or http://www.w3schools.com/jsref/jsref_obj_math.asp
  9. [] must be used instead of . Notation when key is a reserved word or contains space
  10. Anonymous functions are used as:Callback functionsSelf-invoked functions
  11. First alert  undefined – 3Second alert  300 If a variable is used without being declared using ’var’ keyword is added in the window object, thus becomes like a global variable.
  12. Error in page since zzz is undefined.
  13. Alert  undefinedVariable initialized at line 2 of function, but defined everywhere alert(scope);
  14. Useful books are in the notes of the lecture