Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 18

A

PRESENTATION
ON

JavaScript
Aadityanath Maurya(2001200100001)

Department Of Computer Science And Engineering


Institute Of Technology And Management, GIDA
Gorakhpur
Outline

 Introduction
 JavaScript syntax
 Data Types And Variables
 Conditional Statements
 Operators
Introduction
Writing our first code
The very first exercise every programmer goes through is the printing Hello world! message to the console.
Let’s do it with JavaScript: you should use the console.log() statement like in the example:

console.log('Hello world!');

Output using variables


Variable is a piece of memory that has a name and a value.

let age = 23;


console.log('My age is: ', age);

You can see from the above example that we displayed a message My age is: 23 with a
value of the variable age.
why should we use the variables
Variable can store any value, so you can assign it and use it as many times as you need. For example, if you
need value 23 ten times, you can create and use a variable age with this value. Then, if you need to change
your age, you`ll do it once by changing the variable, not changing all 10 occurrences of your value.
Compare two next examples:

console.log('My age is: 23')


console.log('My age is still: 23')
console.log('Now my age is: 23')

let age = 23
console.log('My age is: ', age)
console.log('My age is still: ', age)
console.log('Now my age is: ', age)

If you need to change your age, in the first example, you'll have to do it three times, and in the second, you'll
only change the value of age variable, and then all other occurrences will be changed automatically. That's why
we should use the variables.
JavaScript Syntax
JavaScript Syntax

JavaScript Syntax is a set of rules which defines that our JavaScript program has the correct structure
or not.
In the program we usually perform the following things:
 Declaration of variables
 Assignment of values.
 Computation of values by using operators
//declaration of variables
const firstNumber = 100;
const secondNumber = 5;
const thirdNumber = firstNumber + secondNumber;
console.log(thirdNumber);
JavaScript Values:
A value is the representation of some entity that can be executed by a program.
In JavaScript there are two types of values:
 Fixed values are known as literals.
 Variables values are known as variables.
JavaScript Variables
In JavaScript, variables are used to store data. JavaScript variables are “named storage” for data. We can access the
value of the variable by using variable name. We can use the variables to store different kinds of data like numbers,
text, Boolean, etc.
JavaScript Variables syntax:
A variable in JavaScript has a name, a value, and a memory address.

 The name of the variable distinctively identifies the variable,


 The value refers to data stored in the variable.
 The memory address refers to the memory location of the variable.

const climate ="spring";


console.log(climate);

JavaScript operators
We use operators to performing some actions on the operands. Operands can be variables, numeric literals, or string
literals.

JavaScript Operators Syntax:


We can use the operators between two or more operands to perform a specific task.
// (numerical operator)
const sum = 45 + 2;
console.log(sum);

// (bitwise operator)
const value = 5 | 1;
console.log(value);

// (logical operator)
const isRaining = true;
console.log(isRaining);

//(assignment opearator)
const number = 5;
console.log(number);

// (relational operator)
const isLess = 45 == 10;
console.log(isLess);
Description of the above code:

1. Numerical operators usually perform some numerical actions on the variable.


2. Bitwise operators treat their operands as a set of 32-bit binary digits (zeros and ones) and perform actions.
3. The logical operator returns true or false based on condition.
4. We use assignment operators to assign values to the variable.
5. Relational operators are for checking the relation between operands.

Identifiers in JavaScript
An identifier is simply a name. Identifiers are names given to entities like variables, arrays,
functions, classes, etc. In programming, we often store some values in some variables for later use,
and for this, we give some names to variables.

NOTE:
 Identifire names must start with a number, an underscore(_), or with a dollar sign($).
 Identifire names cannot start with a number.
 JavaScript is case sensitive i.e. ‘Greeting’ is different from ‘greeting’.
 Keywords cannot be used as identifire names.
//valid identifier name
let greeting="hello-world";
console.log(greeting);

//valid identifier name


let _greeting="Good night";
console.log(_greeting);

//valid identifier name


let $greeting="Good morning";
console.log($greeting);

let 1number=10;

//different identifier name from below


let Greeting ="hello-world";
console.log(Greeting);

//valid identifier name from above


let greeting="good-morning";
console.log(greeting);
Note: JavaScript reserves certain identifiers for use by the language itself. These reserved words cannot be used as
regular identifiers.

Naming Identifires:
 Though you can name identifiers in any way you want, it’s a good practice to give a descriptive identifier
name.
 Names should be logical.
 If you are using an identifier for a variable to store the number of students, it is better to use students,
numberOfStudents, or number_of_students rather than x or n.

//valid but not preferable


let n = 10;
console.log(n);

// clear and descriptive name


let numberOfStudents = 10;
console.log(numberOfStudents);

In both cases, the output is the same but the second and the third identifiers are more meaningful.
Reserved Keywords In JavaScript

What are keywords:

JavaScript uses many identifiers as the keywords for language to give power to the language itself. We should
avoid using keywords as identifiers for our programs.
Those keywords are for a specific purpose and perform a specific task that empowers the language itself.

Following are some legal ordinary JavaScript words but they are reserved in strict mode:
implements, let, private, public, yield, interface, package, protected, and static.

Note: This strict context forbids particular actions from being taken and sends more exceptions. The statement
“use strict”; guide the browser to use the Strict mode, which is a reduced and safer feature set of JavaScript
ECMAScript 5 reserved keywords:

Fig.-1
Naming Convention in JavaScript. Case Styles
Naming conventions propose logic when it comes to naming identifiers. No one imposes these naming conventions
as rules, however, they are generally considered in the JavaScript community.

Different Case Styles:


Case explains that how characters are formatted within a word or phrase.

Following the cases that are usually used in Javascript:

 UPPERCASE: In the upper case all the letters are capital, for example, HOURS, and PI. Constants are usually
written in upper-case.
 lowercase: In lower case all the letters are small, for example, name, and age. Variable names having only one
word are usually written in lower-case.
 camelCase: Writing phrases such that each word or abbreviation in the middle of the phrase begins with a capital
letter, for example, variableA, and studentsCount. Functions are usually written in camelCase notation.
 PascalCase: Writing phrases such that each word in the phrase begins with a capital letter, for example,
HumanBeing, and StudentsCount. Classes are usually written in PascalCase
//lowercase
let name = 'bob william';
console.log(name);

//uppercase
let NAME = 'PAUL ANTHONY';
console.log(NAME);

//camelcase
let fullPrice = 1000;
console.log(fullPrice);

//pascal notation
let SoftwareDeveloper = true;
console.log(SoftwareDeveloper);

CONT.........
Conclusion

It was a wonderful and learning experience for me while learning this new programming
language.It gave me the basic understanding of ‘JavaScript’ programming language. The
joy of work and thrill involved while tackling the problem and challenges gave me the feel
of a developer.
I enjoyed each and every bit of work I had put into this.
Internship Organization

 I am doing my course from LearnVern.


 It is a free organization to learn anything like bussiness skills, software development skills,
designing and animation, hardware and networking etc.
 LearnVern teaches students in the user's native language.
References

 https://www.learnvern.com/

 https://codefinity.io/about/
Thank You.....

You might also like