Meta tags:
Headings (most frequently used words):
properties, javascript, the, for, web, property, objects, metadata, naming, manipulating, value, shorthand, syntax, summary, chapter, article, toc, about, getting, started, basics, control, structures, data, types, built, in, operators, functions, classes, error, handling, regular, expressions, general, bom, dom, square, brackets, computed, adding, deleting, checking, if, exists,
Text of the page (most frequently used words):
the (95), user (46), name (39), #properties (36), #property (30), you (26), age (24), and (23), this (21), for (20), can (20), javascript (19), object (19), let (18), are (16), article (12), introduction (12), objects (12), example (12), use (12), that (11), with (10), john (9), doe (9), value (9), when (9), like (8), alert (8), years (8), old (8), not (7), methods (7), they (7), function (7), just (7), newuser (7), now (7), from (7), more (7), how (7), operator (7), please (7), hold (6), have (6), will (6), using (6), then (6), values (6), computed (6), prefix (6), translation (6), operators (6), your (5), here (5), variables (5), but (5), types (5), however (5), variable (5), names (5), square (5), brackets (5), metadata (5), tutorial (4), has (4), been (4), into (4), help (4), used (4), simple (4), see (4), return (4), created (4), parameters (4), notice (4), where (4), our (4), key (4), syntax (4), need (4), declared (4), much (4), full (4), try (4), about (4), any (4), want (4), data (4), prototypes (4), functions (4), translated (3), following (3), language (3), click (3), previous (3), numbers (3), even (3), complex (3), add (3), make (3), bit (3), allows (3), another (3), adding (3), very (3), exists (3), undefined (3), delete (3), what (3), simply (3), assign (3), dynamic (3), course (3), pretty (3), instead (3), these (3), already (3), must (3), contain (3), naming (3), started (3), dutch (3), web (3), regular (3), expressions (3), catching (3), inheritance (3), getters (3), setters (3), translate (2), next (2), strings (2), other (2), reference (2), basically (2), summary (2), complete (2), code (2), way (2), same (2), create (2), based (2), input (2), several (2), pairs (2), often (2), find (2), self (2), creating (2), shorthand (2), may (2), know (2), after (2), comes (2), checking (2), deleting (2), had (2), was (2), declare (2), non (2), only (2), modify (2), normal (2), manipulating (2), generate (2), since (2), everything (2), _name (2), _age (2), specifying (2), well (2), because (2), access (2), space (2), string (2), character (2), rules (2), there (2), sure (2), should (2), saw (2), while (2), concept (2), one (2), original (2), info (2), item (2), vote (2), translating (2), chapter (2), button (2), asp (2), net (2), dom (2), window (2), bom (2), search (2), error (2), conditional (2), errors (2), catch (2), fields (2), extension (2), accessors (2), array (2), basics (2), loops (2), statement (2), toc (2), localization, contact, com, 2007, 2026, fully, languages, preferred, list, czech, store, allowing, huge, deal, some, nice, syntactic, sugar, illustrated, save, few, keystrokes, perhaps, readable, omit, base, case, parameter, rewrite, above, common, doing, things, newly, gives, two, lines, sounds, complicated, consider, mentioned, times, until, specified, delivering, straightforward, making, easy, test, existence, false, true, check, especially, deleted, accomplish, right, before, trying, resulting, being, result, remove, does, exactly, implies, deletes, empty, called, them, exact, means, don, necessarily, all, later, needed, fact, its, existing, far, seen, examples, reading, loop, numbered, showing, once, really, flexible, prop, console, log, output, prop1, prop2, prop3, prop4, prop5, between, evaluated, actual, possibilities, endless, referred, source, hardcoded, programmer, possible, prevents, dot, notation, understand, interpret, part, accessing, collection, talked, work, around, rule, quite, easily, identifier, actually, without, breaking, parsing, engine, special, characters, besides, spaces, start, numeric, longer, descriptive, usage, couple, might, adhere, talk, named, obviously, reflect, piece, usually, exist, global, also, form, introduced, could, dig, deeper, looking, english, logged, page, reloading, login, satisfied, specific, down, reaches, certain, negative, threshold, removed, submit, altered, good, reasons, think, looks, wrong, consult, fluent, point, highlighted, left, border, remember, images, their, titles, inside, get, look, current, status, yellow, untranslated, element, community, working, seems, process, yet, wpf, php5, jquery, html5, css3, webforms, mvc, location, history, script, tag, general, replace, capturing, groups, match, regex, flags, options, throwing, finally, handling, static, classes, multiple, recursive, callback, anonymous, default, optional, chaining, nullish, coalescing, ternary, remainder, logical, increment, decrement, arithmetic, comparison, assignment, json, math, date, number, built, type, conversion, null, tekenreeksen, booleans, switch, control, structures, truthy, falsy, basic, hello, world, tools, getting, libraries, webbrowser, table, contents,
Text of the page (random words):
properties the complete javascript tutorial javascript tutorial toc table of contents chapter article toc introduction properties naming properties square brackets computed properties manipulating properties adding properties deleting properties checking if a property exists property value shorthand syntax summary methods property accessors getters setters prototypes prototypes inheritance extension about javascript what is javascript javascript and the webbrowser javascript libraries getting started the tools you need hello world the basics basic javascript syntax variables truthy falsy control structures the if statement the switch statement loops for and while loops for of and for in data types introduction booleans numbers tekenreeksen null undefined type conversion built in objects introduction number string array the basics array methods date math json operators introduction the assignment operator comparison operators arithmetic operators increment decrement operators modify and assign operators logical operators remainder operator conditional ternary operator nullish coalescing operator optional chaining operator functions introduction function parameters function parameters with default values anonymous functions callback functions recursive functions multiple return values objects introduction properties methods property accessors getters setters prototypes prototypes inheritance extension classes introduction fields methods getters setters inheritance static fields methods error handling introduction catching errors try catch catching throwing errors try catch finally error types conditional catching regular expressions introduction regex flags options search match with regular expressions using capturing groups search replace with regular expressions javascript for web general introduction window dom bom the script tag javascript for web the bom the window object the history object the location object javascript for web the dom introduction javascript asp net mvc asp net webforms c css3 html5 jquery php5 wpf the community is working on translating this tutorial into dutch but it seems that no one has started the translation process for this article yet if you can help us then please click more info if you are fluent in dutch then please help us just point to any untranslated element highlighted with a yellow left border remember that images should have their titles translated as well inside the article and click the translation button to get started or have a look at the current translation status for the dutch language if you see a translation that you think looks wrong then please consult the original article to make sure and then use the vote button to let us know about it metadata please help us by translating the following metadata for the article chapter if they are not already translated if you are not satisfied with the translation of a specific metadata item you may vote it down when it reaches a certain negative threshold it will be removed please only submit an altered translation of a metadata item if you have good reasons to do so please login to translate metadata already logged in please try reloading the page more info looking for the original article in english objects properties in the previous article where we introduced you to the concept of objects we saw an example of how an object could hold one or several properties in this article i want to dig much deeper into the concept of object properties and how they can be used properties are like variables they are declared with a name and used to contain a piece of data but while variables usually exist in the global space a property is declared on an object properties can like variables hold simple types like strings and numbers but also complex values in the form of other objects naming properties now let s talk a bit about how properties can be named obviously you want to use names that will reflect the data that the property should hold we saw an example of this in the previous article where we had properties on our user object to hold a name and an age let user name john doe age 42 of course these are very simple names and you will often find your self using longer and more descriptive names for more complex data however for normal usage there are a couple of rules you might want to adhere to when naming your properties must start with a non numeric character must not contain any spaces must not contain any special characters besides and _ these rules are there to make sure that you can actually declare and access the properties without breaking the javascript parsing engine square brackets however since objects are basically just a collection of key value pairs as we already talked about you can work around this rule quite easily by specifying the property name as a string instead of an identifier we can use pretty much any character we want let user full name john doe a g e 42 of course this now prevents us from using the dot notation to access the property javascript can t understand if we try to reference user full name because it will not interpret the space as part of the property name instead we need to use square brackets when accessing these properties like this let user full name john doe a g e 42 alert user full name is user a g e years old as you can see from the example pretty much everything is now possible when it comes to the name of the property computed properties square brackets can be used when specifying the name of the property as well this is referred to as computed properties because it allows us to let the name of the property be dynamic e g based on input from another source instead of hardcoded by the programmer here s an example of using computed properties let prefix user let user prefix _name john doe prefix _age 42 alert user prefix _name is user prefix _age years old notice how we use the value of the prefix variable to generate the property names since everything between the square brackets are simply evaluated as actual javascript code the possibilities for using computed properties are pretty much endless here s another example of what we can do let user for let i 1 i 5 i user prop i user property i console log user example output prop1 user property 1 prop2 user property 2 prop3 user property 3 prop4 user property 4 prop5 user property 5 in this example we use a loop to generate numbered properties for the object showing you once more that computed properties are really flexible manipulating properties so far we have only seen examples of reading the values of our properties however you can of course modify the values they hold after the object has been declared as if it was a normal variable let user name john doe age 42 user age 43 john doe is 43 years old alert user name is user age years old adding properties objects in javascript are very dynamic this means that you don t necessarily have to declare all the properties when creating the objects you can add more later on if needed in fact its so dynamic that you can simply just assign a value to a non existing property and javascript will just add this property to the object here s an example let user user name john doe user age 42 alert user name is user age years old notice how i create an empty object and then simply assign values to properties called name and age i can then use them in the exact same way as if the properties had been declared when the object was created deleting properties if you need to remove a property from an object we can use the delete operator it does exactly what the name implies it deletes the property from the object here s an example let user name john doe age 42 delete user name result undefined is 42 years old alert user name is user age years old notice how i delete the name property right before trying to use it resulting in user name being undefined checking if a property exists you may need to check if a property exists especially now that we know that they can be deleted after the object has been created javascript comes with the in operator to accomplish just this let user false alert age in user user age 42 true alert age in user as you can see the syntax is very simple and straightforward making it easy for us to test for the existence of a property on our object property value shorthand syntax as mentioned several times by now objects are just key value pairs so up until now we have specified properties by delivering a key name and a value however you will often find your self creating objects where you use a variable as the value using the name of the variable as the key name for the property this sounds a bit complicated but consider the following example where we create our user object based on input from a function function newuser name age let user name name age age return user this is a common way of doing things notice how i use the same names for the parameters name age as i use when adding properties to the newly created user object this gives us the two lines with name name and age age however to save us a few keystrokes and perhaps even make the code a bit more readable javascript allows us to omit the name of the property when we base it on another variable in this case the parameter this allows us to rewrite the above example like this function newuser name age let user name age return user the properties are now created with the name and value from the parameters as illustrated by this complete example function newuser name age let user name age return user let newuser newuser john doe 42 alert newuser name is newuser age years old not a huge deal just some nice syntactic sugar summary properties are like variables but for objects they can be used to store simple types like numbers and strings or even complex types like other objects they can even hold a reference to a function basically allowing you to add methods to an object as we ll see in the next article introduction previous methods next this article has been fully translated into the following languages czech is your preferred language not on the list click here to help us translate this article into your language javascript tutorial com 2007 2026 contact us localization
|