DCIT26 - (LAB-1) Introduction To JavaScript
DCIT26 - (LAB-1) Introduction To JavaScript
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.
• Null and undefined are two distinctly different states for a variable.
• 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?