JavaScript

How To Write JS Code

We can write JS code in HTML Document at the end of "body" tag by using a tag or element "script". as shown bellow.

How to use JavaScript in code

You can use link your JS file by using script tag and src="myscript.js" .

Variables

It is the name of the memory location where we store any data.
We can simply make variable by using var and let keyword .

Here a is a integer variable and b is a sting variable.just like you can make any type of variable.
A JavaScript name must begin with: A letter (A-Z or a-z) A dollar sign ($) Or an underscore (_) Subsequent characters may be letters, digits, underscores, or dollar signs.

NOTE: "var" can use to redeclaring a variable. but "let" can not allow that.
Apply this in our Code Editor.

Comments in JS

JavaScript comments can be used to explain JavaScript code, and to make it more readable.
This comment lines are not executable by browser.
This comments are two types (i)Single-line and (ii) Multi-line comments.

Here a is a integer variable and b is a sting variable.just like you can make any type of variable.
NOTE: Apply this in our Code Editor.

const in JS

The const keyword was introduced in ES6 (2015).
Variables defined with const cannot be Redeclared.
Variables defined with const cannot be Reassigned.

NOTE: Apply this in our Code Editor.

Operators in JS

Operators are the symbles which performs a specific operation with one or more operands.
operands are these values which are use to performs operations.
Operators are two types Unary and Binary

In javascript support varius operators which given bellow.

Assignment Operators

Arithmetic Operators

Comparison Operators

Logical Operators

For more information go to here Click Me.
NOTE: Apply this in our Code Editor.

Data Types in JS

JavaScript has 8 Datatypes
1. String
2. Number
3. Bigint
4. Boolean
5. Undefined
6. Null
7. Symbol
8. Object

The Object Datatype
The object data type can contain:

1. An object
2. An array
3. A date

How to print In Terminal

To print any thing in terminal you can just use console.log("Hello Every One"); then go to inspect element in your browser and open console and see the output.

Strings in JS

A string is a series of characters which use to represent a value.

For more information go to here Click Me.
NOTE: Apply this in our Code Editor. Do not create Strings objects. The new keyword complicates the code and slows down execution speed. String objects can produce unexpected results:

String Functions

String length: to find the length of any string.
String slice(): extracts a part of a string and returns the extracted part in a new string.
String substring(): The difference is that start and end values less than 0 are treated as 0 .
String substr(): substr() is similar to slice().
The difference is that the second parameter specifies the length of the extracted part.
String replace(): The replace() method replaces a specified value with another value in a string.
String toUpperCase(): string is converted to upper case .
String toLowerCase(): string is converted to lower case with.
String concat(): joins two or more strings.
String trim(): it removes whitespace from both sides of a string.
String charAt(): method returns the character at a specified index (position) in a string.
String split(): A string can be converted to an array with the split() method.

For more information go to here Click Me.
NOTE: Apply this in our Code Editor. String search methods are covered in the next chapter.

Conditional Statements

Conditional statements are used to perform different actions based on different conditions.

Use if to specify a block of code to be executed, if a specified condition is true.
Use else to specify a block of code to be executed, if the same condition is false.
Use else if to specify a new condition to test, if the first condition is false.
Use switch to specify many alternative blocks of code to be executed

NOTE: Apply this in our Code Editor.Must use break statement .

Arrays

A Array is a list or collection of some Data Items.
You can assign an array in different types, for more information you can click the note section link click me

NOTE: Apply this in our Code Editor.

Objects

An Object is a type of array which use to store multiple type of data items with a access key.

For more information you can go to a page Click Me
NOTE: Apply this in our Code Editor.

Functions

A JavaScript function is a block of code designed to perform a particular task.
A JavaScript function is executed when "something" invokes it (calls it).

For more information you can go to a page Click Me
NOTE: Apply this in our Code Editor.

Alert, Prompt, Confirm

o Due to Alert in browser Javascript through a pop-up message.
o Due to Prompt you can take user input through browser.
o Confirm is use to take user confirmation through browser.

NOTE: Apply this in our Code Editor.

Loops

Loops are handy, if you want to run the same code over and over again, each time with a different value.
There is different kind of loops are avilable, like for, while and do-while.

For more information you can go to a page Click Me
NOTE: Apply this in our Code Editor.

D O M

When a web page is loaded, the browser creates a Document Object Model of the page.
The HTML DOM model is constructed as a tree of Objects:

For more information you can go to a page Click Me
NOTE: Apply this in our Code Editor.

Events

When an action is happened than the block of code is run.

NOTE: Apply this in our Code Editor.

SetTimeout, ClearTimeout, SetInterval

SetTimeout() : It runs a function after an interval of time.
ClearTimeout() : It stops the function after an interval of time.
SetInterval() : It allows us to run a function repeatedly after every interval of time.

NOTE: Apply this in our Code Editor.

Arrow Function

It is a short cut to call a function in Java Script.

NOTE: Apply this in our Code Editor.


CODE
OUTPUT