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

Data Types

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

Data Types

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

Datatypes

Number
All JavaScript numbers are stored as decimal
numbers (floating point).

Project_pulse

1 var x1= 33.1;


2 console.log(x1)
3 var x2=33
4 console.log(x2)
5
6 //Output: 33.1
7 33
Null
Null means “no value” assign to variable. typeOf null
returns ‘object’. Null is treated as a false value.

Project_pulse

1 let name;
2
3 console.log(name);
4
5 //output: null
6
String Methods
String are used to store textual form of data like word,
sentence. It follows zero based indexing.

Project_pulse

1 let name= “project_pulse”;


2
3 let str = “is”;
4
5 let str= “training programme”;
6
String Methods
length
lastIndexOf()
toLowerCase()
slice()
toUpperCase()
substring()
trim()
toString()
charAt()
replace()
concat()
split()
indexOf()
length
The length property returns the number of characters
in a string. In example above it returns the length of
the string “project_pulse” which is 13 characters

Project_pulse

1 let name= “project_pulse”;


2
3 console.log(name.length);
4
5 //output: 13
6
length
The length property returns the number of characters
in a string. In example above it returns the length of
the string “project_pulse” which is 13 characters

Project_pulse

1 let name= “project_pulse”;


2
3 let named= name.length
4
5 console.log(named);
6
7 //output: 13
toLowerCase()
The toLowerCase() method converts all characters in a
string to lowercase. In this example, it transforms the
string “PROject_puLSE” to “project_pulse”.

Project_pulse

1 let lower= “PROject_puLSE”;


2
3 let lowerConv = lower.toLowerCase();
4
5 console.log(lowerConv);
6
7 //Output: “project_pulse”
toLowerCase()
The toLowerCase() method converts all characters in a
string to lowercase. In this example, it transforms the
string “PROject_puLSE” to “project_pulse”.

Project_pulse

1 let lower= “PROject_puLSE”;


2
3 console.log(lower.toLowerCase());
4
5 //Output: “project_pulse”
6
7
toUpperCase()
The toUpperCase() method converts all characters in a
string to uppercase. In this example, it transforms the
string “PROject_puLSE” to “PROJECT_PULSE”.

Project_pulse

1 let upper= “PROject_puLSE”;


2
3 let upperConv = upper.toUpperCase();
4
5 console.log(upperConv);
6
7 //Output: “PROJECT_PULSE”
toUpperCase()
The toUpperCase() method converts all characters in a
string to uppercase. In this example, it transforms the
string “PROject_puLSE” to “PROJECT_PULSE”.

Project_pulse

1 let upper= “PROject_puLSE”;


2
3 console.log(upper.toUpperCase());
4
5 //Output: “PROJECT_PULSE”
6
7
trim()
The trim() method removes whitespace from both the
begining and end of a string. In this example, it trims the
extra spaces before and after the text “project_pulse”.

Project_pulse

1 let text= “ project_pulse ”;


2
3 console.log(text.trim());
4
5 //Output: “project_pulse”
6
7
trim()
The trim() method removes whitespace from both the
begining and end of a string. In this example, it trims the
extra spaces before and after the text “project_pulse”.

Project_pulse

1 let text= “ project_pulse ”;


2
3 let trimmed= text.trim();
4
5 console.log(trimmed);
6
7 //Output: “project_pulse”
charAt()
The charAt() method in JavaScript returns the character at
a specified index in a string. The index of the first
character is 0, the second is 1, and so on. In the example it
return the character at 1st index.

Project_pulse

1 let text= “project_pulse”;


2
3 let charcter= text.charAt(1);
4
5 console.log(character);
6
7 //Output: “r”
charAt()
The charAt() method in JavaScript returns the character
at a specified index in a string. The index of the first
character is 0, the second is 1, and so on. In the example it
return the character at 1st index.

Project_pulse

1 let text= “project_pulse”;


2
3 console.log(text.charAt(1));
4
5 //Output: “r”
6
7
concat()
The concatenation is the process of joining two or
more strings or arrays. In this example “project” is
joined with “pulse” string.

Project_pulse

1 let text1 = "project";


2
3 let text2 = "pulse";
4
5 let result = text1.concat(" ", text2);
6
7 console.log(result);
8
0 //Output: “project_pulse”
concat()
The concatenation is the process of joining two or
more strings or arrays. In this example “project” is
joined with “pulse” string.

Project_pulse

1 let text1 = "project";


2
3 let text2 = "pulse";
4
5 console.log(text1.concat(" ", text2));
6
7 //Output: “project_pulse”
8
indexOf()
The indexOf() method finds the first occuurence of a
specified value in a string and returns its position. In
this example, it returs the position of string “p” in the
message, which is 8.

Project_pulse

1 let str="PROject_pulse";
2
3 let index=str.indexOf("p");
4
5 console.log(conv);
6
7 //Output: “8”
indexOf()
The indexOf() method finds the first occuurence of a
specified value in a string and returns its position. In
this example, it returs the position of string “p” in the
message, which is 8.

Project_pulse

1 let str="PROject_pulse";
2
3 console.log(str.indexOf(“p”));
4
5 //Output: “8”
6
7
lastIndexOf()
The lastIndexOf() method in JavaScript returns the
index of the last occurrence of a specified value in a
string or array. It searches from the end to the
beginning and returns -1 if the value is not found.

Project_pulse

1 let text = "project pulse is a


2 training programme";
3
4 let result = text.lastIndexOf("p");
5
6 console.log(result);
7
8 //Output: “28”
lastIndexOf()
The lastIndexOf() method in JavaScript returns the
index of the last occurrence of a specified value in a
string or array. It searches from the end to the
beginning and returns -1 if the value is not found.

Project_pulse

1 let text = "project pulse is a


2 training programme";
3
4 console.log(text.lastIndexOf("p"));
5
6 //Output: “28”
7
slice()
The slice() method in JavaScript is used to extract a
section of an array or string and return it as a new
array or string, without modifying the original.

Project_pulse

1 const fruits = ["Banana", "Orange",


2 "Lemon", "Apple", "Mango"];
3
4 const citrus = fruits.slice(1, 3);
5
6 console.log(citrus);
7
8 //Output: “[ 'Orange', 'Lemon' ]”
slice()
The slice() method in JavaScript is used to extract a
section of an array or string and return it as a new
array or string, without modifying the original.

Project_pulse

1 const fruits = ["Banana", "Orange",


2 "Lemon", "Apple", "Mango"];
3
4 console.log(fruits.slice(1, 3));
5
6 //Output: “[ 'Orange', 'Lemon' ]”
7
substring()
The substring() method in JavaScript extracts characters
between two indices from a string, returning the
substring from the start to the end index (exclusive).

Project_pulse

1 const str = "project_pulse";


2
3 const result = str.substring(7, 12);
4
5 console.log(result);
6
7 //Output: “_puls”
substring()
The substring() method in JavaScript extracts
characters between two indices from a string,
returning the substring from the start to the end
index (exclusive).

Project_pulse

1 const str = "project_pulse";


2
3 console.log(str.substring(7, 12));
4
5 //Output: “_puls”
6
7
toString()
The toString() method in JavaScript converts an object
to a string representation. This method is commonly
used to convert objects to their string representations,
especially when concatenating strings or logging objects

Project_pulse

1 let text = "project_pulse";


2
3 let result = text.toString();
4
5 console.log(result);
6
7 //Output: “project_pulse”
toString()
The toString() method in JavaScript converts an object
to a string representation. This method is commonly
used to convert objects to their string representations,
especially when concatenating strings or logging objects

Project_pulse

1 let text = "project_pulse";


2
3 console.log(text.toString());
4
5 //Output: “project_pulse”
6
7
replace()
The replace() method searches a string for a specified
value and replaces it with a new value. In this example,
it replaces the word “pulse” with “script”

Project_pulse

1 let text = "project_pulse";


2
3 let result = text.replace("pulse","string");
4
5 console.log(result);
6
7 //Output: “project_string”
replace()
The replace() method searches a string for a specified
value and replaces it with a new value. In this example,
it replaces the word “pulse” with “script”

Project_pulse

1 let text = "project_pulse";


2
3 let result = text.replace("pulse","string");
4
5 console.log(result);
6
7 //Output: “project_string”
split()
The split() method divides a string into an array of
substrings based on a specified delimiter. In this
example, it splits the message into an array of words
using the space characters as the delimiter.

Project_pulse

1 let text = "project pulse is a


2 training programme";
3
4 console.log(text.split(" "));
5
6 //Output: [ 'project', 'pulse', 'is',
7 'a', 'training', 'programme' ]
split()
The split() method divides a string into an array of
substrings based on a specified delimiter. In this
example, it splits the message into an array of words
using the space characters as the delimiter.

Project_pulse

1 let text = "project pulse is a


2 training programme";
3
4 let result = text.split(" ");
5
6 console.log(result);
7
8 //Output: [ 'project', 'pulse', 'is',
9 'a', 'training', 'programme' ]

You might also like