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

DCIT26 - (LAB-1) Introduction To JavaScript

The document introduces JavaScript syntax and tools, including variables, operators, conditional statements, loops and functions. It explains where JavaScript code can be included, basic syntax rules, and provides examples of variables, comparison operators, logical operators, conditional statements, while and for loops, and function creation and calling.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

DCIT26 - (LAB-1) Introduction To JavaScript

The document introduces JavaScript syntax and tools, including variables, operators, conditional statements, loops and functions. It explains where JavaScript code can be included, basic syntax rules, and provides examples of variables, comparison operators, logical operators, conditional statements, while and for loops, and function creation and calling.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

INTRODUCTION

TO JAVASCRIPT
Basic syntax and tools

DCIT 26 - BSCS 3
WHAT IS JAVASCRIPT?
JavaScript (JS) is an object-oriented, dynamically typed, client-side scripting language that runs directly
inside the browser.
VISUAL STUDIO CODE
Download and install VS Code.
WRITING JAVASCRIPT
WHERE DOES
JAVASCRIPT GO?
JavaScript can be included in three ways: inline, embedded or external.
WRITING JAVASCRIPT
Variables, operators, conditional statements, loop and functions.
SYNTACTIC GOTCHAS
• Everything is type sensitive.

• The scope of variables in blocks is not supported.

• Null and undefined are two distinctly different states for a variable.

• Semicolons are not required, but are permitted (and encouraged).

• There is no integer type, only number.


VARIABLES
• Variables in JavaScript are dynamically typed.

• To declare a variable, we use the let keyword, the name, and a semi-colon(;).

• Assignment can happen at declaration-time by appending the value to the declaration, or at run time
with the operator (=).
COMPARISON OPERATORS
• Comparison operators compares two values and returns a Boolean value: true or false.

• This includes equals (==), exactly equals, including type (===), less than (<), greater that(>),
not equal (!=) and not equal in either value or type (!==).
LOGICAL OPERATORS
• Logical operators includes and (&&), or (||), and not (!).
CONDITIONAL STATEMENT
• JS conditional structure is almost identical to that of Java and C.

• The condition to test is contained within ( ) brackets with the body contained in { }
blocks.

• Optional else if statements can follow, with an else ending the branch.
EXAMPLE OF CONDITIONAL STATEMENT
LOOP
• Like conditionals, loops use the ( ) and { } blocks to define the condition and the body of
the loop.
EXAMPLE OF WHILE LOOP
EXAMPLE OF FOR LOOP
FUNCTIONS
• Functions are the building block for modular code in JavaScript.

• They are defined by using the reserved word function and then the function name and
(optional) parameters.
CREATING AND CALLING OF JS FUNCTIONS
EXAMPLE #1: A function to raise x to the yth power
CREATING AND CALLING OF JS FUNCTIONS
EXAMPLE #2: A function to greet the user along with their name.
THANKS!
Does anyone have any questions?

You might also like