Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
18 views

JavaScript Statements

Uploaded by

Naruto Uzumaki
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

JavaScript Statements

Uploaded by

Naruto Uzumaki
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

JavaScript

1 JavaScript Statements
2 JavaScript Statements
 A computer program is a list of “instructions” to be “executed” by a computer.

 These programming instructions are called statements.

 A JavaScript program is a list of programming statements.

 JavaScript statements are composed of:

 Values,

 Operators,

 Expressions,

 Keywords, and

 Comments.
3 JavaScript Values
 The JavaScript syntax defines two types of values: Fixed values and Variable values

 Fixed values are called Literals.

 Variable values are called Variables.

JavaScript Literals
 Numbers are written with or without decimals

 Strings are text, written within double or single quotes.


4 JavaScript Variables
Variables are containers for storing data. JavaScript variables can be declared in 4 ways:

 Automatically

 Using var

 Using let

 Using const
5 JavaScript Identifiers
All JavaScript variables must be identified with unique names called identifiers.

 Names can contain letters, digits, underscores, and dollar signs.

 Names must begin with a letter.

 Names can also begin with $ and _ (underscore).

 Names are case sensitive (y and Y are different variables).

 Reserved words (like JavaScript Keywords) cannot be used as names.


6 JavaScript Data Type
JavaScript has 8 Datatypes The Object Datatype are:

 String  An Object

 Number  An array

 Bigint  A date

 Boolean

 Undefined

 Null

 Symbol

 Object
7 JavaScript Data Type Examples
8 JavaScript Operators
There are different types of JavaScript operators:

 Arithmetic operators

 Assignment operators

 Comparison operators

 String operators

 Logical operators

 Bitwise operators

 Ternary operators

 Type operators
9 JavaScript Arithmetic Operators
Arithmetic operators are used to perform arithmetic on numbers.
10 JavaScript Assignment Operators
Assignment operators assign values to JavaScript variables.
11 JavaScript Comparison Operators
12 JavaScript Logical Operators

JavaScript Type Operators


13 JavaScript Keywords
 JavaScript statements often start with a keyword to identify the JavaScript action to be performes.
14 JavaScript Expression
 Semicolons separate JavaScript statements.

 Add a semicolon at the end of each executable statement.

 When separated by semicolons, multiple statements on one line are allowed.

 JavaScript ignores multiple spaces (can add white space to be readable).

 A good practice is to put spaces around operators ( = + - * / ).

 Programmers often like to avoid code lines longer than 80.

 If a JavaScript statement does not fit on one line, the best practice to break it is after an operator.

 JavaScript statements can be grouped together in code block, inside curly bracket { … }.

 The purpose of code blocks is to define statements to be executed together.


15 JavaScript Comments
 Comments can be used to explain JavaScript code, and to make it more readable.

 Comments can also be used to prevent execution, when testing alternative codes.

 Single line comments start with //

 Multi-line comments start with /* and end with */ .


16 JavaScript Example 1
https://supersimple.dev/projects/amazon/
17 JavaScript Basics (Exercise)
 Do this Exercise in the Console (right-click > Inspect > Console)

 Use alert(…); to display ‘Good Morning !’ in a popup.

 Calculate 20 + 5 in the Console.

 Create the text “My name” and another text “Simon”. Using concatenation, add these two strings together to
create the text: ‘My name is Simon’.

 You order a T-shirt for $10, socks for $8, and dinner plates for $20. Use JavaScript to calculate the total cost of
your order.

 At a restaurant, you order 1 coffee ($5) and 1 bagel ($3). Using Math, calculate the total cost, and using
concatenation, create the text: ‘Total cost: $ ___’ (replace ___ with the total you calculated).
18

Apply JavaScript Statements.

You might also like