Javascript
What is JavaScript?
- Javascript is a language used to create dynamic content for websites
- HTML adds structure to a web page, CSS styles it, and Javascript brings it to life by allowing users to interact with elements on the page.
- Javascript is also used on the server side to access databases, file handling and security features to send responses to browsers.
What can Javascript do?
- JS gives HTML designers a programming tool.
- JS can put dynamic texts into an HTML page.
- JS can read and write HTML elememts.
JAVASCRIPT VARIABLES.
- Variables are 'containers' for storing information.
- Js variables are used to hold values or expressions.
- A variable can have a short name, like x, or a more descriptive name like carname.
- Rules for Javascript variable names;
- Variable names are case sensitive(y and Y are two different variables).
- Variable names must begin with a letter or the underscore character.
Declaring Javascript variables.
- You can declare javascript variable with the var statement; Var x; var carname;
- You can also assign values to the variables when you declare them: var x = 5; var carname = "Scorpio"
Data types
- Numbers - Are values that can be processed and calculated. You don't enclose them in quotation marks and can either be - or +.
- Strings - Are a series of letters or numbers enclosed in quotation marks. e.g "greetings" or "fun".
- Boolean (true or false) - Let's you evaluate whether a condition meets or doesn't meet the specified criteria.
- Null - It is an empty value. Null is not the same as 0 -- 0 is a real, calculable number, whereas null is the abscence of any value.
Javascript operators.
- The operator = is used to assign values.
- The operator + is used to add values together.
- The operator - is used to subtract values.
JavaScript comparison and logical operators.
Comparison operators.
- Are used in logical statements to determine equality or differece between values or variables.
- Given that x=5, the table explains the comparison operators. | Operator | Description | Examples | |:----------|:---------------------:|----------:| | == | is equal to | x==8 is false | | === | is exactly equal to(value & type) | x===5 is true | | != | is not equal | x!= 8 is true |
- How can it be used:
- Can be used in conditional statements to compare values and take action depending on the results
Logical operators.
- Are used to determine the logic between values or variables.