Javascript intro chapter four epes4.pptx

hamzazalah 7 views 10 slides Sep 13, 2024
Slide 1
Slide 1 of 10
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10

About This Presentation

Golis University


Slide Content

Chapter 4 Variables, Operators and Datatypes

Variables Variables are used to store data values . Variables have: Name Datatype Value JavaScript uses the keywords var and/or let to declare variables. An equal sign/assignment operator (=) is used to assign values to variables. Example: var age; age=15; Note: JavaScript does not interpret LET or Let as the keyword let.

Operators JavaScript uses: Arithmetic operators Assignment operator Comparison operators Logical operators

JavaScript Keywords JavaScript keywords are used to identify actions to be performed. Some JavaScript keywords are: let var

JavaScript Identifiers Identifiers are used to name variables and keywords. Identifiers can be short names (like x and y) or more descriptive names (age, lastname , customeraddress ). The rules for the naming JavaScript Variables JavaScript name can contain: A letter (a – z or A – Z) A dollar sign ($) An underscore(_) JavaScript name must begin with letter. Note: JavaScript identifiers are all case sensitive.

Data Types Unlike its predecessor languages C, C++ and Java, JavaScript does not require variables to have a declared type before they can be used in a script. A variable in JavaScript can contain a value of any data type, and in many situations JavaScript automatically converts between values of different types for you.

Declaring a JavaScript variable Creating a variable in JavaScript is called “declaring” a variable. var and let keywords are declaring variable. Example: var age; or let age;

Arithmetic operators Addition & Subtraction <script>     let x=5;     let y=3;     let z= x + y;     let m= x - y; console.log(z); console.log(m);  </script> Multiplication & Division <script>     let x=5;     let y=3;     let z= x * y;     let m= x / y; console.log(z); console.log(m);  </script>

Comparison/Relational Operators  <script>     let x=5;     let y=3;     console. log(x> y); console.log(x<y);  </script>

Logical operator  <script>     let x= true && true;     let y= true || false; let z=!false;     console.log(x); console.log(y); console.log(z);  </script>