100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.6 TrustPilot
logo-home
Summary

Summary JavaScript

Rating
-
Sold
2
Pages
11
Uploaded on
16-12-2021
Written in
2021/2022

Summary of the concept of Javascript. all the information to be known in this file. of the elective box creating value using social media by Jan Moons.

Institution
Course









Whoops! We can’t load your doc right now. Try again or contact support.

Written for

Institution
Study
Course

Document information

Uploaded on
December 16, 2021
Number of pages
11
Written in
2021/2022
Type
Summary

Subjects

Content preview

JAVASCRIPT
VARIABLES
New variables in JavaScript are declared using one of three keywords: let, const, or var.

let allows you to declare block-level variables. The declared variable is available from the block it
is enclosed in.

let a;


let name = 'Simon';


The following is an example of scope with a variable declared with let:

// myLetVariable is *not* visible out here




for (let myLetVariable = 0; myLetVariable < 5; myLetVariable++) {


// myLetVariable is only visible in here


}




// myLetVariable is *not* visible out here


const allows you to declare variables whose values are never intended to change. The variable is
available from the block it is declared in.

const Pi = 3.14; // variable Pi is set


Pi = 1; // will throw an error because you cannot change a constant variable.


varis the most common declarative keyword. It does not have the restrictions that the other two
keywords have. This is because it was traditionally the only way to declare a variable in
JavaScript. A variable declared with the var keyword is available from the function it is declared in.

var a;


var name = 'Simon';


An example of scope with a variable declared with var:

// myVarVariable *is* visible out here

, for (var myVarVariable = 0; myVarVariable < 5; myVarVariable++) {


// myVarVariable is visible to the whole function


}




// myVarVariable *is* visible out here


If you declare a variable without assigning any value to it, its type is undefined.

An important difference between JavaScript and other languages like Java is that in JavaScript,
blocks do not have scope; only functions have a scope. So if a variable is defined using var in a
compound statement (for example inside an if control structure), it will be visible to the entire
function. However, starting with ECMAScript 2015, let and const declarations allow you to create
block-scoped variables.


OPERATORS

JavaScript's numeric operators are +, -, *, / and % which is the remainder operator (which is the
same as modulo.) Values are assigned using =, and there are also compound assignment
statements such as += and -=. These extend out to x = x operator y.

x += 5;


x = x + 5;


You can use ++ and -- to increment and decrement respectively. These can be used as a prefix or
postfix operators.

The + operator also does string concatenation:

'hello' + ' world'; // "hello world"


If you add a string to a number (or other value) everything is converted into a string first. This
might trip you up:

'3' + 4 + 5; // "345"


3 + 4 + '5'; // "75"


Adding an empty string to something is a useful way of converting it to a string itself.

Comparisons in JavaScript can be made using <, >, <= and >=. These work for both strings and
numbers. Equality is a little less straightforward. The double-equals operator performs type
coercion if you give it different types, with sometimes interesting results:

Get to know the seller

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
Handelswetenschapperugent Universiteit Gent
Follow You need to be logged in order to follow users or courses
Sold
145
Member since
5 year
Number of followers
102
Documents
14
Last sold
1 week ago
Handelswetenschapper @Ugent

3.4

10 reviews

5
3
4
1
3
4
2
1
1
1

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions