0% found this document useful (0 votes)
4 views4 pages

JavaScript Basics: Variables & Operations

The document provides an introduction to JavaScript, covering how to run JavaScript in different environments, the concept of variables, their types, naming conventions, and best practices. It also explains mathematical operations, shorthand notations, type conversions, and the use of specific methods like parseInt, parseFloat, and toFixed. Additionally, it discusses the modulus operator for calculating remainders.

Uploaded by

Kawsar Ahmed
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)
4 views4 pages

JavaScript Basics: Variables & Operations

The document provides an introduction to JavaScript, covering how to run JavaScript in different environments, the concept of variables, their types, naming conventions, and best practices. It also explains mathematical operations, shorthand notations, type conversions, and the use of specific methods like parseInt, parseFloat, and toFixed. Additionally, it discusses the modulus operator for calculating remainders.

Uploaded by

Kawsar Ahmed
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

16-1 Introduction to Javascript, Run Javascript in VS Code

●​ In the browser’s development environment, javascript can be run in the ‘console’ section.
●​ To run js code in VS terminal, type ‘node [Link]’ and it show the output.
●​ For online IDE to run and debug web code, use this website CodePen: Online Code
Editor and Front End Web Developer Community

16-2 What is variable, five things you need to declare a variable

●​ In computer programming, a variable or scalar is a storage location (identified by a


memory address) paired with an associated symbolic name, which contains some known
or unknown quantity of information referred to as a value; or in easy terms, a variable is
a container for a particular type of data (like integer, float, String and etc...).
●​ To define a variable, there is 5 things to declare.​
i) The keyword ‘var’
ii) Consized and contextual variable name.
iii) A ‘=’ sign.
iv) value that will assign to the variable.
v) A semicolon (;) at the end.

Ex:
var price = 21;
var age = 13;
var temperature = 37;

16-3 Variable type, Numeric, String, Boolean

●​ String type variable value must be inside the double quotation or single quotation.
●​ To enter a block of letters inside double quotation or single quotation, mark the block of
letter and press shift+” or shift+’
●​ Basically, Javascript variables are three types.
i) Numeric variable. (Contains NUMERIC values)
ii) String variable. (Contains TEXT values)
iii) Boolean variable. (Contains TRUE or FALSE)

16-4 Variable name naming convention and best practice

●​ JavaScript Reserved Words:


In JavaScript, you cannot use these reserved words as variables, labels, or function
names. Here is the list of the reserved word for javascript.​
JavaScript Reserved Words
●​ Javascript variable name must be a single word.
●​ Multiple blocks of words can be used as variable by underscore inside them. (Ex: var
my_name). The recommended way to define a variable in javascript is to follow
camelCase text where the first letter of the word starts with lower case and every
other word will start upper case and no space between them. (Ex: var
myOfficeAddress). Just to notice, the hyphen inside the word is not allowed for defining
variable names.
●​ Some constant values like PI which are sometimes declared with full upper case letters.
(Ex: PI = 3.1416)
●​ The variable name cannot be declared inside the quotation mark.
●​ A variable name cannot be starts number.

16-5 Simple Mathematical operations in JavaScript

●​ [Link](var) is used to show the value inside var


●​ Here is the mathematical operator in detail: JavaScript Operators

16-6 (advanced) Mathematical operation shorthand

●​ A variable that is initialized before is not required to initialize again with var.
●​ Price1 += 44; means price1 = price1 + 44; This the shorthand form of math operators.
●​ Price1 -= 44; means price1 = price1 - 44; This the shorthand form of math operators.
●​ Increment operator ‘++’ increases the value by one.
●​ Decrement Operator ‘--’ decreases the value by one.

16-7 (advanced) Integer float parseInt parseFloat type conversion

●​ The parseInt() function parses a string argument and returns an integer of the specified
radix (the base in mathematical numeral systems).
●​ The parseFloat() function parses an argument (converting it to a string first if needed)
and returns a floating-point number.

16-8 Different variable types and use toFixed with parseFloat

●​ To know the data type of a variable, write [Link](typeof varName); in the terminal.
●​ toFixed() is a Number method that is used to convert a number to fixed-point notation
(rounding the result where necessary) and return its value as a string. For details,
JavaScript toFixed() Method

16-9 Module Summary and remainder modulus

●​ Declaring variable.
●​ Variable Type.
●​ The remainder operator (%) returns the remainder left over when one operand is divided
by a second operand. It always takes the sign of the dividend. It is also known as
Modulus Operator.

You might also like