Javascript is the world's most popular programming language. it is mainly used in the web-development. JavaScript is abbreviated as JS. It was invented by Brendan Eich of Netscape initially and was contributed to the ECMA script(Wikipedia). JavaScript is mainly used with HTML and CSS. JavaScript gives you more power to your webpage. It is easy to learn the language.
Javascript is applied and is used to creative interactive website. It is mainly used for:
Client side Validation
Dynamic drop-down menu
Displaying date and time
Displaying pop-up window
__
JavaScript Basics
JavaScript Comments
Single-Line Comments
We use // and texts between // will be ignored.
//Heading
//Change Paragraph//
Multi-Line Comments
We us /* and end end with */
/*The family had a lot of staff going on
and chose to seek counselling */
JavaScript Variables
there are different ways to declare a variable
-using Var
-using let
-using const
-using nothing
var x = 3
var y = 4
let x = 1
let y = 2
const num1= sh.100
const num2 = sh.320
Javascript operators
JavaScript Arithmetic Operators
Arithmetic operators are used to perform arithmetic on numbers:
Operator Description
- Addition
- Subtraction
- Multiplication ** Exponentiation (ES2016) / Division % Modulus (Division Remainder) ++ Increment -- Decrement How to work with the operators
let x = 1
let y = 5
let z = x+y
the Rest applies(subtraction, multiplication and division) as the example shown above.
Javascript Data Types
JavaScript variables can hold different data types: numbers, strings, objects and more:
let age = 16; // Number
let firstName = "Christine"; // String
let x = {firstName:"Levi", lastName:"Mbithi"}; // Object
JavaScript Function
function myFunction(p1, p2) {
return p1 * p2; // The function returns the product of p1 and p2
}
Function Invocation
The code inside the function will execute when "something" invokes (calls) the function:
- When an event occurs (when a user clicks a button)
- When it is invoked (called) from JavaScript code
- Automatically (self invoked)
Top comments (0)