SlideShare a Scribd company logo
Javascript
We’ll review the following topics
• Data types
• Arithmetic operators
• Condition & Loops
• Functions
• Arrays
• Objects & JSON
Introduction
• Javascript is an interpreted language, browser interpet it
  on the fly. Unlike compiled language.
• Javascript is written in a text file with the extension „.js‟ or
  as part of an html document.
• The text contains the commands that make up the
  program.
• Javascript is a standart that each vendor can follow
  entitled with: ECMA-262
• Javascript is a very popular language and it allows us to
  create dynamic & interactive websites.
Hello World!
Type the following code in a new document titled
  HelloWorld.html
mind case sensitive.

<script type="text/javascript">

   // our main function Hello World
   function helloWorld() {
       alert('Hello World!');
   }

   helloWorld();

</script>
Variables & data types
Variable who?
• Variable is a piece of data that contains information while
  our code is executing.
• Variables can be used to store data and retrieve data
  later on.
• Each variable has a data type (number, string, date).
• Javascript is an implicit language and don‟t need to
  specify the variable data type.
Variables & data types
Declaring variables
To declare an variable specify var before the name e.g:
var {NAME};
Declaring a var named “num”:
var num;
Declaring multiple variables in one var statement
var name, address;
Initializing variables with initial value:
var x = 100, message = 'Hello';
Variables & data types
Variable scope
Variable scope confines the variable to the block(curly
brackets) in which he was created:
Global scope:
<script type="text/javascript">
    var x = 10;
</script>
Variable y is known only inside function “doSomething”:
<script type="text/javascript">
    function doSomething() {
        var y = 99;
    }
    alert(y); //Uncaught ReferenceError: y is not defined
</script>
Variables & data types
assignment
Using Assignment we can store data in a given variable.
The sign = means assignment. e.g:

Place the value 3 inside the variable num:
num = 3;
One row declaration + assignment:
var num = 1;



                                                          Switch var
Variables & data types
Data types

Javascript base data types:
•   string
•   number
•   boolean
•   function
•   Array
•   object
Variables & data types
// string
var companyName = ‘Google';

// number
var pi = 3.14;
var year = 2013;

// boolean
var flag = true;
var FALSE = false;

// function
var sayHello = function () {
    alert('hello world!');
}

// array
var numberArray = [1, 2, 3];
var animals = new Array("cat", "dog", "mouse", "lion");

// object / json
var person = {
    name: 'Barack Hussein Obama II',
    age: '51',
    title: '44th President of the United States'
Operators
Arithmetic operation:
<script>
    var x = 10, y = 20;

    var addition = x + y;
    var subtraction = y - x;
    var multiplication = x * y;
    var division = x / y;
    var remainder = x % y;
</script>
if-else statement
if-else allows us to control the flow of our program.

if (condition){
    //code
}

if (condition){
    //code
} else {
    //code
if-else statement
if-else
Example:
var currentTime = 8;

if (currentTime > 6 && currentTime <= 7) {
    alert('wake up!');
} else if (currentTime > 12 && currentTime <= 13) {
    alert('launch time!');
} else {
    alert('spare time at last...');
}
Boolean Conditions

Types of Boolean comparison:
Boolean Conditions
<script>
    var num1 = 10;
    var num2 = 20;

   if (num1 > num2) {
       alert('num1 is bigger');
   }

   var num2bigger = num1 > num2;
   if (num2bigger) {
       alert('num2 is bigger');
   }

   if (num1 == num2) {
       alert('num1 equal num2');
   }

    if (num1 != num2) {
        alert('num1 not equal num2');
    }
</script>
Boolean Conditions
More operators, and / or / not
Boolean Conditions
Conditional operators and / or / not
Boolean Conditions
<script>
    var rabbitName = 'archimedes',
         age = 1;


   if (rabbitName == 'archimedes' && age == 1) {
       alert('hello Archie, welcome home!');
   }

   if (age == 0 || age == 1) {
       alert('hello junior rabbit!');
   }

   var isYoung = age < 5;

   if (!isYoung) {
       alert(rabbit is old!');
   }

</script>
Math
Math class encapsulate a lot of usefull methods:

• Math.abs(x) absolute value of a Decimal number.
• Math.max(x1,x2) & Math.min(x1, x2) Return the number
  with the highest/lowest value
• Math.pow(x, y) – xy
• Math.sqrt(x) square root of a number
• Math.random() random number between 0 and 1
• Math.PI - 3.14159
for loop
Loops can execute a block of code a number of times.

Syntax
for(<initial>; <condition> ; <update>) {
    // code goes here
}

Example
for (var i = 0; i < 10 ; i++) {
    document.write('this is row ' + i + '<br />');
}
for loop
Code
for (var i = 0; i < 10 ; i++) {
    document.write('this is row ' + i + '<br />');
}
Output
this is row 0
this is row 1
this is row 2
this is row 3
this is row 4
this is row 5
this is row 6
this is row 7
this is row 8
this is row 9



                                                     for-pyramid
While loop
The while loop loops through a block of code as long as a
specified condition is true.

Syntax
while (condition) {
    // code to repeat
}
While loop
Code
var count = 0;
while (count < 10) {
    document.write('Count: ' + count + '<br />');
    count++;
}
Output
Count:   0
Count:   1
Count:   2
Count:   3
Count:   4
Count:   5
Count:   6
Count:   7
Count:   8
Count:   9
Functions
A function is a block of code that will be executed when it is
called, Both of the following functions declarations are exactly
the same, functions are indeed variables:

function clickMe() {
    alert('clicked!');
}

var clickMe = function () {
    alert('clicked!');
Functions
Function can have parameters & return value with the
return keyword.

function sum(x, y) {
    return x * y;
}

var six = sum(2, 3);
alert(sum(5, 10));
sum(5, sum(5, 5));
Arrays
• The Array object is used to store multiple values in a
  single variable.
• Array can add & remove values
• Array can store diffrent data types
• Array are Zero-based
• Examples:
Arrays
Declaring Arrays & Initialization

var   myArray1   =   new Array(10, 22);
var   myArray2   =   new Array();
var   myArray3   =   [];
var   myArray4   =   [1, 2, 3];
var   myArray5   =   new Array("cat", "dog", "mouse", "lion");
var   myArray6   =   new Array(10); // predefined size array
var   myArray7   =   [1, "hello world!", 1.24, function () { }, [1, 2, 3],
                      null, undefined, { a: 1, b: 2 }, document.body];
Arrays
Arrays can be accessed via index:

var animals = new Array("Cat", "Dog", "Mouse", "Lion");


Get the first value of the array:
var cat = animals[0];


Assign value to the third index of the array:
animals[2] = 'Giraffe';
Arrays
Get the current items in the array with the length property:

var animals = new Array("Cat", "Dog", "Mouse", "Lion");
var animalsCount = animals.length;
// animalsCount = 4
Push a new item to the array:
Animals.push('Kangaroo‘);
Checking the length again:
animalsCount = animals.length;
// animalsCount = 5
Iterate over the values of the array and use alert to show them;
for (var i = 0; i < animals.length; i++) {
    alert(animals[i]);
}



                                                                   Sum-array
Objects
Objects are a special kind of data in javascript.
Objects can be used with properties to assign data:
Example of an object:
var person = {
    name: 'Barack Hussein Obama II',
    age: '51',
    title: '44th President of the United States'
}
Objects
Access to Object properties:

var person = {
    name: 'Barack Hussein Obama II',
    age: '51',
    title: '44th President of the United States'
}

alert(person.name); // Barack Hussein Obama II
alert(person['name']); // Barack Hussein Obama II

person.age = 51;
person['age'] = 51;
Objects
Often in web development we Get JSON data and need
to manipulate it:
{
    'employees': [
            { "firstName": "John", "lastName": "Doe" },
            { "firstName": "Anna", "lastName": "Smith" },
            { "firstName": "Peter", "lastName": "Jones" }




Then we can dynamiccaly create html from our data object.
Summary
we've covered Javascript Basics.
With javascript we can build more dynamic & interactive
website with rich user experience.

Javascript is fun & simple


Written by shlomi komemi
Shlomi@komemi.com

More Related Content

What's hot

JavaScript Programming
JavaScript ProgrammingJavaScript Programming
JavaScript Programming
Sehwan Noh
 
Lab #2: Introduction to Javascript
Lab #2: Introduction to JavascriptLab #2: Introduction to Javascript
Lab #2: Introduction to Javascript
Walid Ashraf
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
Andres Baravalle
 
Javascript
JavascriptJavascript
Javascript
Vibhor Grover
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to Javascript
ambuj pathak
 
JavaScript - Chapter 8 - Objects
 JavaScript - Chapter 8 - Objects JavaScript - Chapter 8 - Objects
JavaScript - Chapter 8 - Objects
WebStackAcademy
 
Javascript
JavascriptJavascript
Javascript
Rajavel Dhandabani
 
Java script
Java scriptJava script
Java script
Sadeek Mohammed
 
JavaScript Tutorial
JavaScript  TutorialJavaScript  Tutorial
JavaScript Tutorial
Bui Kiet
 
JavaScript - Chapter 3 - Introduction
 JavaScript - Chapter 3 - Introduction JavaScript - Chapter 3 - Introduction
JavaScript - Chapter 3 - Introduction
WebStackAcademy
 
Javascript
JavascriptJavascript
Javascript
Nagarajan
 
Javascript
JavascriptJavascript
Javascript
Manav Prasad
 
Javascript
JavascriptJavascript
Javascript
D V BHASKAR REDDY
 
Javascript functions
Javascript functionsJavascript functions
Javascript functions
Alaref Abushaala
 
JavaScript - Chapter 5 - Operators
 JavaScript - Chapter 5 - Operators JavaScript - Chapter 5 - Operators
JavaScript - Chapter 5 - Operators
WebStackAcademy
 
jQuery for beginners
jQuery for beginnersjQuery for beginners
jQuery for beginners
Arulmurugan Rajaraman
 
JavaScript guide 2020 Learn JavaScript
JavaScript guide 2020 Learn JavaScriptJavaScript guide 2020 Learn JavaScript
JavaScript guide 2020 Learn JavaScript
Laurence Svekis ✔
 
JavaScript
JavaScriptJavaScript
JavaScript
Vidyut Singhania
 
JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...
JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...
JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...
Edureka!
 

What's hot (20)

JavaScript Programming
JavaScript ProgrammingJavaScript Programming
JavaScript Programming
 
Lab #2: Introduction to Javascript
Lab #2: Introduction to JavascriptLab #2: Introduction to Javascript
Lab #2: Introduction to Javascript
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
Javascript
JavascriptJavascript
Javascript
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to Javascript
 
JavaScript - Chapter 8 - Objects
 JavaScript - Chapter 8 - Objects JavaScript - Chapter 8 - Objects
JavaScript - Chapter 8 - Objects
 
Javascript
JavascriptJavascript
Javascript
 
Java script
Java scriptJava script
Java script
 
JavaScript Tutorial
JavaScript  TutorialJavaScript  Tutorial
JavaScript Tutorial
 
Java script
Java scriptJava script
Java script
 
JavaScript - Chapter 3 - Introduction
 JavaScript - Chapter 3 - Introduction JavaScript - Chapter 3 - Introduction
JavaScript - Chapter 3 - Introduction
 
Javascript
JavascriptJavascript
Javascript
 
Javascript
JavascriptJavascript
Javascript
 
Javascript
JavascriptJavascript
Javascript
 
Javascript functions
Javascript functionsJavascript functions
Javascript functions
 
JavaScript - Chapter 5 - Operators
 JavaScript - Chapter 5 - Operators JavaScript - Chapter 5 - Operators
JavaScript - Chapter 5 - Operators
 
jQuery for beginners
jQuery for beginnersjQuery for beginners
jQuery for beginners
 
JavaScript guide 2020 Learn JavaScript
JavaScript guide 2020 Learn JavaScriptJavaScript guide 2020 Learn JavaScript
JavaScript guide 2020 Learn JavaScript
 
JavaScript
JavaScriptJavaScript
JavaScript
 
JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...
JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...
JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...
 

Viewers also liked

TechCBT: JavaScript Arrays in Depth
TechCBT: JavaScript Arrays in DepthTechCBT: JavaScript Arrays in Depth
TechCBT: JavaScript Arrays in Depth
Tech CBT
 
Javascript - Array - Creating Array
Javascript - Array - Creating ArrayJavascript - Array - Creating Array
Javascript - Array - Creating Array
Samuel Santos
 
Keeping Eloquent Eloquent
Keeping Eloquent EloquentKeeping Eloquent Eloquent
Keeping Eloquent Eloquent
Colin DeCarlo
 
Understanding Object Oriented Javascript - Coffee@DBG June
Understanding Object Oriented Javascript - Coffee@DBG JuneUnderstanding Object Oriented Javascript - Coffee@DBG June
Understanding Object Oriented Javascript - Coffee@DBG June
Deepu S Nath
 
JavaScript Arrays
JavaScript Arrays JavaScript Arrays
JavaScript Arrays
Reem Alattas
 
JavaScript Functions
JavaScript FunctionsJavaScript Functions
JavaScript Functions
Brian Moschel
 

Viewers also liked (7)

Books
BooksBooks
Books
 
TechCBT: JavaScript Arrays in Depth
TechCBT: JavaScript Arrays in DepthTechCBT: JavaScript Arrays in Depth
TechCBT: JavaScript Arrays in Depth
 
Javascript - Array - Creating Array
Javascript - Array - Creating ArrayJavascript - Array - Creating Array
Javascript - Array - Creating Array
 
Keeping Eloquent Eloquent
Keeping Eloquent EloquentKeeping Eloquent Eloquent
Keeping Eloquent Eloquent
 
Understanding Object Oriented Javascript - Coffee@DBG June
Understanding Object Oriented Javascript - Coffee@DBG JuneUnderstanding Object Oriented Javascript - Coffee@DBG June
Understanding Object Oriented Javascript - Coffee@DBG June
 
JavaScript Arrays
JavaScript Arrays JavaScript Arrays
JavaScript Arrays
 
JavaScript Functions
JavaScript FunctionsJavaScript Functions
JavaScript Functions
 

Similar to Javascript 101

Handout - Introduction to Programming
Handout - Introduction to ProgrammingHandout - Introduction to Programming
Handout - Introduction to Programming
Cindy Royal
 
Java script
Java scriptJava script
Java script
Adrian Caetano
 
Javascript variables and datatypes
Javascript variables and datatypesJavascript variables and datatypes
Javascript variables and datatypesVarun C M
 
10. session 10 loops and arrays
10. session 10   loops and arrays10. session 10   loops and arrays
10. session 10 loops and arraysPhúc Đỗ
 
JavaScript - An Introduction
JavaScript - An IntroductionJavaScript - An Introduction
JavaScript - An Introduction
Manvendra Singh
 
Stuff you didn't know about action script
Stuff you didn't know about action scriptStuff you didn't know about action script
Stuff you didn't know about action scriptChristophe Herreman
 
javascript-variablesanddatatypes-130218094831-phpapp01.pdf
javascript-variablesanddatatypes-130218094831-phpapp01.pdfjavascript-variablesanddatatypes-130218094831-phpapp01.pdf
javascript-variablesanddatatypes-130218094831-phpapp01.pdf
AlexShon3
 
The JavaScript Programming Language
The JavaScript Programming LanguageThe JavaScript Programming Language
The JavaScript Programming Language
Mohammed Irfan Shaikh
 
Game Design and Development Workshop Day 1
Game Design and Development Workshop Day 1Game Design and Development Workshop Day 1
Game Design and Development Workshop Day 1
Troy Miles
 
Introduction to TypeScript
Introduction to TypeScriptIntroduction to TypeScript
Introduction to TypeScript
Tomas Corral Casas
 
Expert JavaScript tricks of the masters
Expert JavaScript  tricks of the mastersExpert JavaScript  tricks of the masters
Expert JavaScript tricks of the masters
Ara Pehlivanian
 
GDI Seattle - Intro to JavaScript Class 2
GDI Seattle - Intro to JavaScript Class 2GDI Seattle - Intro to JavaScript Class 2
GDI Seattle - Intro to JavaScript Class 2
Heather Rock
 
Java script introducation & basics
Java script introducation & basicsJava script introducation & basics
Java script introducation & basicsH K
 
Getting started with ES6
Getting started with ES6Getting started with ES6
Getting started with ES6
Nitay Neeman
 
Ajax and JavaScript Bootcamp
Ajax and JavaScript BootcampAjax and JavaScript Bootcamp
Ajax and JavaScript Bootcamp
AndreCharland
 

Similar to Javascript 101 (20)

CSC PPT 13.pptx
CSC PPT 13.pptxCSC PPT 13.pptx
CSC PPT 13.pptx
 
Handout - Introduction to Programming
Handout - Introduction to ProgrammingHandout - Introduction to Programming
Handout - Introduction to Programming
 
Java script
Java scriptJava script
Java script
 
Javascript variables and datatypes
Javascript variables and datatypesJavascript variables and datatypes
Javascript variables and datatypes
 
10. session 10 loops and arrays
10. session 10   loops and arrays10. session 10   loops and arrays
10. session 10 loops and arrays
 
JavaScript - An Introduction
JavaScript - An IntroductionJavaScript - An Introduction
JavaScript - An Introduction
 
Stuff you didn't know about action script
Stuff you didn't know about action scriptStuff you didn't know about action script
Stuff you didn't know about action script
 
javascript-variablesanddatatypes-130218094831-phpapp01.pdf
javascript-variablesanddatatypes-130218094831-phpapp01.pdfjavascript-variablesanddatatypes-130218094831-phpapp01.pdf
javascript-variablesanddatatypes-130218094831-phpapp01.pdf
 
The JavaScript Programming Language
The JavaScript Programming LanguageThe JavaScript Programming Language
The JavaScript Programming Language
 
C# basics
C# basicsC# basics
C# basics
 
Php & my sql
Php & my sqlPhp & my sql
Php & my sql
 
Game Design and Development Workshop Day 1
Game Design and Development Workshop Day 1Game Design and Development Workshop Day 1
Game Design and Development Workshop Day 1
 
csc ppt 15.pptx
csc ppt 15.pptxcsc ppt 15.pptx
csc ppt 15.pptx
 
Introduction to TypeScript
Introduction to TypeScriptIntroduction to TypeScript
Introduction to TypeScript
 
Expert JavaScript tricks of the masters
Expert JavaScript  tricks of the mastersExpert JavaScript  tricks of the masters
Expert JavaScript tricks of the masters
 
GDI Seattle - Intro to JavaScript Class 2
GDI Seattle - Intro to JavaScript Class 2GDI Seattle - Intro to JavaScript Class 2
GDI Seattle - Intro to JavaScript Class 2
 
Java script introducation & basics
Java script introducation & basicsJava script introducation & basics
Java script introducation & basics
 
jQuery introduction
jQuery introductionjQuery introduction
jQuery introduction
 
Getting started with ES6
Getting started with ES6Getting started with ES6
Getting started with ES6
 
Ajax and JavaScript Bootcamp
Ajax and JavaScript BootcampAjax and JavaScript Bootcamp
Ajax and JavaScript Bootcamp
 

Recently uploaded

Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
CatarinaPereira64715
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
Fwdays
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
Abida Shariff
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
Bhaskar Mitra
 

Recently uploaded (20)

Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
 

Javascript 101

  • 1. Javascript We’ll review the following topics • Data types • Arithmetic operators • Condition & Loops • Functions • Arrays • Objects & JSON
  • 2. Introduction • Javascript is an interpreted language, browser interpet it on the fly. Unlike compiled language. • Javascript is written in a text file with the extension „.js‟ or as part of an html document. • The text contains the commands that make up the program. • Javascript is a standart that each vendor can follow entitled with: ECMA-262 • Javascript is a very popular language and it allows us to create dynamic & interactive websites.
  • 3. Hello World! Type the following code in a new document titled HelloWorld.html mind case sensitive. <script type="text/javascript"> // our main function Hello World function helloWorld() { alert('Hello World!'); } helloWorld(); </script>
  • 4. Variables & data types Variable who? • Variable is a piece of data that contains information while our code is executing. • Variables can be used to store data and retrieve data later on. • Each variable has a data type (number, string, date). • Javascript is an implicit language and don‟t need to specify the variable data type.
  • 5. Variables & data types Declaring variables To declare an variable specify var before the name e.g: var {NAME}; Declaring a var named “num”: var num; Declaring multiple variables in one var statement var name, address; Initializing variables with initial value: var x = 100, message = 'Hello';
  • 6. Variables & data types Variable scope Variable scope confines the variable to the block(curly brackets) in which he was created: Global scope: <script type="text/javascript"> var x = 10; </script> Variable y is known only inside function “doSomething”: <script type="text/javascript"> function doSomething() { var y = 99; } alert(y); //Uncaught ReferenceError: y is not defined </script>
  • 7. Variables & data types assignment Using Assignment we can store data in a given variable. The sign = means assignment. e.g: Place the value 3 inside the variable num: num = 3; One row declaration + assignment: var num = 1; Switch var
  • 8. Variables & data types Data types Javascript base data types: • string • number • boolean • function • Array • object
  • 9. Variables & data types // string var companyName = ‘Google'; // number var pi = 3.14; var year = 2013; // boolean var flag = true; var FALSE = false; // function var sayHello = function () { alert('hello world!'); } // array var numberArray = [1, 2, 3]; var animals = new Array("cat", "dog", "mouse", "lion"); // object / json var person = { name: 'Barack Hussein Obama II', age: '51', title: '44th President of the United States'
  • 10. Operators Arithmetic operation: <script> var x = 10, y = 20; var addition = x + y; var subtraction = y - x; var multiplication = x * y; var division = x / y; var remainder = x % y; </script>
  • 11. if-else statement if-else allows us to control the flow of our program. if (condition){ //code } if (condition){ //code } else { //code
  • 12. if-else statement if-else Example: var currentTime = 8; if (currentTime > 6 && currentTime <= 7) { alert('wake up!'); } else if (currentTime > 12 && currentTime <= 13) { alert('launch time!'); } else { alert('spare time at last...'); }
  • 13. Boolean Conditions Types of Boolean comparison:
  • 14. Boolean Conditions <script> var num1 = 10; var num2 = 20; if (num1 > num2) { alert('num1 is bigger'); } var num2bigger = num1 > num2; if (num2bigger) { alert('num2 is bigger'); } if (num1 == num2) { alert('num1 equal num2'); } if (num1 != num2) { alert('num1 not equal num2'); } </script>
  • 17. Boolean Conditions <script> var rabbitName = 'archimedes', age = 1; if (rabbitName == 'archimedes' && age == 1) { alert('hello Archie, welcome home!'); } if (age == 0 || age == 1) { alert('hello junior rabbit!'); } var isYoung = age < 5; if (!isYoung) { alert(rabbit is old!'); } </script>
  • 18. Math Math class encapsulate a lot of usefull methods: • Math.abs(x) absolute value of a Decimal number. • Math.max(x1,x2) & Math.min(x1, x2) Return the number with the highest/lowest value • Math.pow(x, y) – xy • Math.sqrt(x) square root of a number • Math.random() random number between 0 and 1 • Math.PI - 3.14159
  • 19. for loop Loops can execute a block of code a number of times. Syntax for(<initial>; <condition> ; <update>) { // code goes here } Example for (var i = 0; i < 10 ; i++) { document.write('this is row ' + i + '<br />'); }
  • 20. for loop Code for (var i = 0; i < 10 ; i++) { document.write('this is row ' + i + '<br />'); } Output this is row 0 this is row 1 this is row 2 this is row 3 this is row 4 this is row 5 this is row 6 this is row 7 this is row 8 this is row 9 for-pyramid
  • 21. While loop The while loop loops through a block of code as long as a specified condition is true. Syntax while (condition) { // code to repeat }
  • 22. While loop Code var count = 0; while (count < 10) { document.write('Count: ' + count + '<br />'); count++; } Output Count: 0 Count: 1 Count: 2 Count: 3 Count: 4 Count: 5 Count: 6 Count: 7 Count: 8 Count: 9
  • 23. Functions A function is a block of code that will be executed when it is called, Both of the following functions declarations are exactly the same, functions are indeed variables: function clickMe() { alert('clicked!'); } var clickMe = function () { alert('clicked!');
  • 24. Functions Function can have parameters & return value with the return keyword. function sum(x, y) { return x * y; } var six = sum(2, 3); alert(sum(5, 10)); sum(5, sum(5, 5));
  • 25. Arrays • The Array object is used to store multiple values in a single variable. • Array can add & remove values • Array can store diffrent data types • Array are Zero-based • Examples:
  • 26. Arrays Declaring Arrays & Initialization var myArray1 = new Array(10, 22); var myArray2 = new Array(); var myArray3 = []; var myArray4 = [1, 2, 3]; var myArray5 = new Array("cat", "dog", "mouse", "lion"); var myArray6 = new Array(10); // predefined size array var myArray7 = [1, "hello world!", 1.24, function () { }, [1, 2, 3], null, undefined, { a: 1, b: 2 }, document.body];
  • 27. Arrays Arrays can be accessed via index: var animals = new Array("Cat", "Dog", "Mouse", "Lion"); Get the first value of the array: var cat = animals[0]; Assign value to the third index of the array: animals[2] = 'Giraffe';
  • 28. Arrays Get the current items in the array with the length property: var animals = new Array("Cat", "Dog", "Mouse", "Lion"); var animalsCount = animals.length; // animalsCount = 4 Push a new item to the array: Animals.push('Kangaroo‘); Checking the length again: animalsCount = animals.length; // animalsCount = 5 Iterate over the values of the array and use alert to show them; for (var i = 0; i < animals.length; i++) { alert(animals[i]); } Sum-array
  • 29. Objects Objects are a special kind of data in javascript. Objects can be used with properties to assign data: Example of an object: var person = { name: 'Barack Hussein Obama II', age: '51', title: '44th President of the United States' }
  • 30. Objects Access to Object properties: var person = { name: 'Barack Hussein Obama II', age: '51', title: '44th President of the United States' } alert(person.name); // Barack Hussein Obama II alert(person['name']); // Barack Hussein Obama II person.age = 51; person['age'] = 51;
  • 31. Objects Often in web development we Get JSON data and need to manipulate it: { 'employees': [ { "firstName": "John", "lastName": "Doe" }, { "firstName": "Anna", "lastName": "Smith" }, { "firstName": "Peter", "lastName": "Jones" } Then we can dynamiccaly create html from our data object.
  • 32. Summary we've covered Javascript Basics. With javascript we can build more dynamic & interactive website with rich user experience. Javascript is fun & simple Written by shlomi komemi Shlomi@komemi.com