100% tevredenheidsgarantie Direct beschikbaar na je betaling Lees online óf als PDF Geen vaste maandelijkse kosten
logo-home
summary of javascript Creating Value with Websites €2,99
In winkelwagen

Samenvatting

summary of javascript Creating Value with Websites

 0 keer verkocht
  • Vak
  • Instelling

summary of javascript Creating Value with Websites

Voorbeeld 2 van de 11  pagina's

  • 16 december 2021
  • 11
  • 2021/2022
  • Samenvatting
avatar-seller
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:

Dit zijn jouw voordelen als je samenvattingen koopt bij Stuvia:

Bewezen kwaliteit door reviews

Bewezen kwaliteit door reviews

Studenten hebben al meer dan 850.000 samenvattingen beoordeeld. Zo weet jij zeker dat je de beste keuze maakt!

In een paar klikken geregeld

In een paar klikken geregeld

Geen gedoe — betaal gewoon eenmalig met iDeal, creditcard of je Stuvia-tegoed en je bent klaar. Geen abonnement nodig.

Direct to-the-point

Direct to-the-point

Studenten maken samenvattingen voor studenten. Dat betekent: actuele inhoud waar jij écht wat aan hebt. Geen overbodige details!

Veelgestelde vragen

Wat krijg ik als ik dit document koop?

Je krijgt een PDF, die direct beschikbaar is na je aankoop. Het gekochte document is altijd, overal en oneindig toegankelijk via je profiel.

Tevredenheidsgarantie: hoe werkt dat?

Onze tevredenheidsgarantie zorgt ervoor dat je altijd een studiedocument vindt dat goed bij je past. Je vult een formulier in en onze klantenservice regelt de rest.

Van wie koop ik deze samenvatting?

Stuvia is een marktplaats, je koop dit document dus niet van ons, maar van verkoper Handelswetenschapperugent. Stuvia faciliteert de betaling aan de verkoper.

Zit ik meteen vast aan een abonnement?

Nee, je koopt alleen deze samenvatting voor €2,99. Je zit daarna nergens aan vast.

Is Stuvia te vertrouwen?

4,6 sterren op Google & Trustpilot (+1000 reviews)

Afgelopen 30 dagen zijn er 69988 samenvattingen verkocht

Opgericht in 2010, al 15 jaar dé plek om samenvattingen te kopen

Begin nu gratis

Laatst bekeken door jou


€2,99
  • (0)
In winkelwagen
Toegevoegd