0% found this document useful (0 votes)
11 views3 pages

JavaScript Data Types Explained

The document outlines different data types in JavaScript, including numbers, strings, booleans, and variables. It explains how to create strings, handle quotes within them, and the rules for naming variables. Additionally, it discusses concatenation of strings and the conversion between strings and numbers using the + operator and Number() function.

Uploaded by

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

JavaScript Data Types Explained

The document outlines different data types in JavaScript, including numbers, strings, booleans, and variables. It explains how to create strings, handle quotes within them, and the rules for naming variables. Additionally, it discusses concatenation of strings and the conversion between strings and numbers using the + operator and Number() function.

Uploaded by

myuvaraja17
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Types of Data;

Numbers
 A number is represented by a numeric character.
 NaN also comes under the number
Strings
 A string is just a series of letters and other symbols enclosed inside
of quote marks.
 You can use either double quote marks ("hello world") or
single quote marks ('hello world') or backtick (`hello world`)
to enclose the string, but you must make sure to use the same type
of quote mark at the beginning and end of the string.
When I try to create a string with a quote mark in it, my program doesn’t
work. Why is that?
 When the JavaScript interpreter encounters the first quote mark, it
says to itself, “Ahh, here comes a string.” When it reaches a
matching quote mark, it figures it has come to the end of the string.
 There are a couple of ways to get around this conundrum. The
easiest method is to use single quotes to enclose a string that has
one or more double quotes inside it. For example, 'He said,
"Hello."' is a valid string—the single quotes create the string, and
the double quotes inside are a part of the string. Likewise, you can
use double quotes to enclose a string that has a single quote inside
it: "This isn’t fair" for example.
 Another method is to tell the JavaScript interpreter to just treat the
quote mark inside the string literally—that is, treat the quote mark
as part of the string, not the end of the string. You do this using
something called an escape character(\). Example like this: "He
said, \"Hello.\ "".
Booleans
 It is either one of two values: true or false.
Variable;
 A variable is a way to store information so that you can later use
and manipulate it.
 Creating a variable is a two-step process that involves declaring
the variable and naming it.
Rules you must follow when naming variables;
 Variable names must begin with a letter, $, or _.
 Variable names can only contain letters, numbers, $, and _.
 Variable names are case-sensitive.
 Avoid keywords.
If you want to declare a bunch of variables at one time, you can do it in a
single line of code like this: var score, players, game_time;
Tip: To save typing, you can declare multiple variables with a single var
keyword, like this:
var x, y, z;
You can even declare and store values into multiple variables in one
JavaScript statement:
var isSuperHero=true, isAfraidOfHeights=false;
NOTE : Multiplication (the * symbol) and division (the / symbol) take
precedence over addition (+) and subtraction (-). Any math that’s
performed inside parentheses happens first.
Combining Strings:
 Combining strings is called concatenation, and you accomplish it
with the + operator.
Combining Numbers and Strings;
 If both operands are numbers, + means numeric addition.
 If either operand is a string, + means string concatenation.
 Multiply 2 and the string 'eggs'. If you try this example, you’ll end up
with a special JavaScript value NaN, which stands for “not a
number.”
 Use the + operator to do two things: convert the number to a string
and concatenate it with the other string.- JavaScript interpreter
recognizes that there is a string involved, so it realizes it won’t be
doing any math (no addition).
 That input is treated like a string—'2'.
 You add + to the beginning of the string that contains a
number like this:
o var numOfShoes = '2';
o var numOfSocks = 4;
o var totalItems = +numOfShoes + numOfSocks;
 or
o var totalItems = Number(numOfShoes) + numOfSocks;
 Number( ) converts a string to a number if possible. (If the string is
just letters and not numbers, you get the NaN value to indicate that
you can’t turn letters into a number.)
-Read till 52 – Day 13-10-2025

You might also like