0% found this document useful (0 votes)
16 views

java script

java script

Uploaded by

anshbhawsar665
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

java script

java script

Uploaded by

anshbhawsar665
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Java script notes

What is JavaScript?

JS is a programming language. We use it to give instructions to the


computer.

way of output:
1. Console.log();
2. Alert();

Way to input:

prompt()
Ex.

const userInput = prompt("Please enter your name:");

Variable Rules:

1. Variable names are case sensitive; “a” & “A” is different.


2. Only letters, digits, underscore( _ ) and $ is allowed. (not even
space) Only a letter, underscore( _ ) or $ should be 1st character.
3. Reserved words cannot be variable names. Apna College.

let, const & var :

1. Var: Variable can be re-declared & updated. A global scope


variable.
2.let : Variable cannot be re-declared but can be updated. block
scope variable.
3.const : Variable cannot be re-declared or updated. A block scope
variable.

Comments in JS Part of Code which is not executed:

1. // for single line comment.


2. /* */ for multiple line comment.

Operators in JS Used to perform some operation on data

1.Arithmetic Operators: +, -, *, /
2.Assignment Operators: +=, -=, *=, %=, *=.
3.Comparison Operators: Equal to == .Not equal to != >, >=, <,
<= Equal to & type Not equal to & type === !==

3. Logical Operators: Logical AND: &&


Java script notes

4. Logical OR : ||
5. Logical not: !

Conditional Statements:

To implement some condition in the code

1. if statement.
2. else statement.
3. If-else statement.

Loops in js:

Loops are used to execute a piece of code again & again

1. for Loop:

for (let i = 1; i <= 5; i++)


{ console.log("apna college"); }

2. while Loop:

while (condition)
{ // do some work }

3. Do-while loop:

do
{ // do some work }
while (condition).

4. for-of Loop :

for (let val of strVar)


{ //do some work }

Ex.strvar=[12,34,23,12,34];

5. for-in Loop:

for (let key in objVar)


{ //do some work }
Java script notes

Strings in JS:

String is a sequence of characters used to represent


text.

Create String :
let str = “Apna College“;

String Length: str.length.

String Indices: Apna College str[0], str[1], str[2].

Template Literals in JS:


A way to have embedded expressions in strings.

`this is a template literal`

String Interpolation :

To create strings by doing substitution of placeholders

`string text ${expression} string text` .

String Methods in JS:

These are built-in functions to manipulate a string.

1. str.toUpperCase( )

2. str.toLowerCase( )

3. str.trim( ) // removes whitespaces Ap

4. str.slice(start, end?) // returns part of string

5. str1.concat( str2 ) // joins str2 with str1

6. str.replace( searchVal, newVal )

7. str.charAt( idx )
Java script notes

Arrays in JS:
Collections of items Create Array

1.let heroes = [ “ironman”, “hulk”, “thor”, “batman” ];


2.let marks = [ 96, 75, 48, 83, 66 ];
3.let info = [ “rahul”, 86, “Delhi” ];

Array Methods:

1. Push( ) : add to end

2. Pop( ) : delete from end & return

3. toString( ) : converts array to string

4. Concat( ) : joins multiple arrays & returns result

5. Unshift( ) : add to start

6. shift( ) : delete from start & return

7. Slice( ) : returns a piece of the array slice( startIdx, endIdx )

8. Splice( ) : change original array (add, remove, replace)


splice( startIdx, delCount, newEl1…).

Functions in JS:

You might also like