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

Basics of Javascript

This document provides an overview of basic JavaScript concepts including: - Math operations in JavaScript follow the order of BODMAS and calculate from left to right. Functions like Math.round() and Math.floor() can round numbers. - Strings can be created with single quotes, double quotes, or backticks. Strings can be concatenated and numbers can be coerced to strings. - Variables are containers that store values and are declared with keywords like let, const, and var. Variables follow camelCase naming conventions.

Uploaded by

Laiba Jawaid
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)
23 views

Basics of Javascript

This document provides an overview of basic JavaScript concepts including: - Math operations in JavaScript follow the order of BODMAS and calculate from left to right. Functions like Math.round() and Math.floor() can round numbers. - Strings can be created with single quotes, double quotes, or backticks. Strings can be concatenated and numbers can be coerced to strings. - Variables are containers that store values and are declared with keywords like let, const, and var. Variables follow camelCase naming conventions.

Uploaded by

Laiba Jawaid
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
You are on page 1/ 8

BASICS OF JAVASCRIPT

 Giving instructions to a computer (Code)


 The computer follows our instructions (running the code)

Math in JavaScript
 / This is use for division. * This is use for multiplication.
 In JavaScript math operation are done according to BODMAS/Order of Operation
and JavaScript follows the same rules multiply and divide are done first. Add and
subtract are done after .
 One thing to note is that multiply and divide have the same priority so if we have
both in a calculation it will calculate from left to right
 Add and subtract also have the same priority if we have both in the calculation it will
also calculate from left to right
 We can use brackets to control which part of the calculation gets done first
 weird behavior of math in JavaScript first we need to learn some terminology in
programming whole numbers like 2-3 and four are called integers decimal numbers
like 2.2 and 2.5 are called floating point numbers or floats and unfortunately
computers have a problem working with floats
CODE FOR ROUNDING A NUMBER IN JAVASCRIPT: Math.round(2.2)
Note: Make sure you use capital M since JavaScript is case sensitive
CODE FOR DISPLAYING POPUP: alert (‘helllo’)
CODE TO REMOVE ALL THE HTML AND JUST DISPLAY ONE WORD:
document.body.innerHTML=('manahil')

The Math.floor() method rounds a number DOWN to the nearest integer.

STRINGS
A String represent text.

We can add text as well eg ‘some’+’text’+’any’ result sometextany. This is called


concatenation ( combine strings together)
‘hello’+3
hello3
We add a string and a number JavaScript will automatically convert this number into a string
so this gets converted into a string hello + the string 3 and then it combines them together
into the string hello 3 this feature is called type coercion or automatic type conversion
String also follows the order of operation in JavaScript.
There are ways to create a string the first way is to use double quote which we already know
second way is to use single quote .Single quotes are mostly preferred. Third way to create
string is to use backtick. Strings created with backtick are called template strings.
There is one situation where double quote are very useful. For example if we type ‘ I ‘m
learning JavaScript’ this won't work as single quote with end the string earlier
'i'm learning java'

"i'm learning java"

Character:
1.Letter
2. Number
3.Symbol
4.Escape character a. \’ this is to represent text
b.\n newline character used to create newline
console.log is used to display value or string in console.

VARIABLES
Variable is a container in which we can save value (number or string) for later use
let is used to create variable.

SYNTAX FOR VARIABLE:


 Word let create a new variable.
 Then we gave a name to variable. We can name variable almost anything we want
except for few restrictions:
1.We can’t use let as variable name. However, we can use let1 or let2.
2.Can’t start with a number. However, can be used in the middle and the end.
3. Can’t use special character in the variable except: $

 To save something inside the variable we use = sign


 Then add value we want to save

SYNTAX FOR RE-ASSIGNING VALUE TO VARIABLE


variable1 = 5 ;

All the variable name should use camel case. It is the standard for
JavaScript.

Camel is the most useful naming convection for javascript.


Pascal case is only used in one feature.
Kebab case is not supported in javascript. However, It is mostly used
in HTML and CSS
Snake case is used in other languages but not in javascript.
3 WAYS TO CREATE VARIABLE
 Let(can be change later)
 Const(we can’t change it’s value later. It will remain constant)
 Var(can be change later)
BOOLEANS

LOGICAL OPERTORS : They help to combine Boolean values .Eg: && , ||


Not done

TERNARY OPERATOR

PREQUISITE FOR CREATING A GAME


(Rock,Paper,Scissors)
FUNCTIONS

You might also like