You can edit almost every page by Creating an account and confirming your email.

JavaScript Basics: Difference between revisions

From EverybodyWiki Bios & Wiki
WikiMasterBot2 (talk | contribs)
m Moved page from wikipedia:en:Draft:JavaScript Basics ([[Edithistory:|history]])
WikiMasterBot2 (talk | contribs)
m automatic correction by IA
 
(18 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{AFC submission|d|e|u=PantherPedia|ns=118|decliner=Mcmatter|declinets=20220829021031|reject=yes|ts=20220829012447}} <!-- Do not remove this line! -->
{{AFC comment|1=[[WP:NOTHOWTO]] [[User:Mcmatter|McMatter]] <sup>([[User talk:Mcmatter|talk]])</sup>/<sub>([[Special:Contributions/Mcmatter|contrib]])</sub> 02:10, 29 August 2022 (UTC)}}
{{AFC comment|1=[[WP:NOTHOWTO]] [[User:Mcmatter|McMatter]] <sup>([[User talk:Mcmatter|talk]])</sup>/<sub>([[Special:Contributions/Mcmatter|contrib]])</sub> 02:10, 29 August 2022 (UTC)}}


Line 9: Line 7:
{{AfC topic|stem}}
{{AfC topic|stem}}


= JavaScript Basics =
== JavaScript Basics ==


=== Variables ===
=== Variables ===
Variables<ref>{{Citation |title=Variable (computer science) |date=2022-08-19 |url=https://en.wikipedia.org/w/index.php?title=Variable_(computer_science)&oldid=1105315140 |work=Wikipedia |language=en |access-date=2022-08-29}}</ref> are data stored as a value in a named space. Variables can be used as a mathematical constant,<ref>{{Citation |title=Constant (mathematics) |date=2022-06-02 |url=https://en.wikipedia.org/w/index.php?title=Constant_(mathematics)&oldid=1091159181 |work=Wikipedia |language=en |access-date=2022-08-29}}</ref> to use in math commands to generate a user output,<ref name=":0">{{Citation |title=Input/output |date=2022-08-28 |url=https://en.wikipedia.org/w/index.php?title=Input/output&oldid=1107158004 |work=Wikipedia |language=en |access-date=2022-08-29}}</ref> such as e,<ref>{{Citation |title=e (mathematical constant) |date=2022-08-26 |url=https://en.wikipedia.org/w/index.php?title=E_(mathematical_constant)&oldid=1106854025 |work=Wikipedia |language=en |access-date=2022-08-29}}</ref> which has a value of 2.718281828459045. To declare a new constant, type the keyword "const",<ref>{{Citation |title=const (computer programming) |date=2022-08-20 |url=https://en.wikipedia.org/w/index.php?title=Const_(computer_programming)&oldid=1105407141 |work=Wikipedia |language=en |access-date=2022-08-29}}</ref> and add the [[JavaScript syntax#Declaration and assignment|assignment declaration]]. Add the value to declare the constant. Note that constants cannot be changed afterward, which should be self-explanatory. Normal variables work the same way, and can be changed accordingly depending on user input. Variables can also hold strings,<ref>{{Citation |title=String (computer science) |date=2022-08-01 |url=https://en.wikipedia.org/w/index.php?title=String_(computer_science)&oldid=1101756832 |work=Wikipedia |language=en |access-date=2022-08-29}}</ref> which is useful for input such as authorization<ref>{{Citation |title=Authorization |date=2022-08-18 |url=https://en.wikipedia.org/w/index.php?title=Authorization&oldid=1105166484 |work=Wikipedia |language=en |access-date=2022-08-29}}</ref> or for a search engine.<ref>{{Citation |title=Search engine |date=2022-08-28 |url=https://en.wikipedia.org/w/index.php?title=Search_engine&oldid=1107150189 |work=Wikipedia |language=en |access-date=2022-08-29}}</ref> Variables can also identify as undefined<ref>{{Citation |title=Undefined value |date=2021-12-09 |url=https://en.wikipedia.org/w/index.php?title=Undefined_value&oldid=1059485044 |work=Wikipedia |language=en |access-date=2022-08-29}}</ref> or null.<ref>{{Citation |title=Null character |date=2022-08-10 |url=https://en.wikipedia.org/w/index.php?title=Null_character&oldid=1103680343 |work=Wikipedia |language=en |access-date=2022-08-29}}</ref>
Variables<ref>{{Citation |title=Variable (computer science) |date=2022-08-19 |url=https://en.wikipedia.org/w/index.php?title=Variable_(computer_science)&oldid=1105315140 |work=Wikipedia |language=en |access-date=2022-08-29}}</ref> are data stored as values in a named space. Variables can be used as mathematical constants,<ref>{{Citation |title=Constant (mathematics) |date=2022-06-02 |url=https://en.wikipedia.org/w/index.php?title=Constant_(mathematics)&oldid=1091159181 |work=Wikipedia |language=en |access-date=2022-08-29}}</ref> used in math commands to generate user output,<ref name=":0">{{Citation |title=Input/output |date=2022-08-28 |url=https://en.wikipedia.org/w/index.php?title=Input/output&oldid=1107158004 |work=Wikipedia |language=en |access-date=2022-08-29}}</ref> such as e,<ref>{{Citation |title=e (mathematical constant) |date=2022-08-26 |url=https://en.wikipedia.org/w/index.php?title=E_(mathematical_constant)&oldid=1106854025 |work=Wikipedia |language=en |access-date=2022-08-29}}</ref> which has a value of 2.718281828459045. To declare a new constant, type the keyword "const",<ref>{{Citation |title=const (computer programming) |date=2022-08-20 |url=https://en.wikipedia.org/w/index.php?title=Const_(computer_programming)&oldid=1105407141 |work=Wikipedia |language=en |access-date=2022-08-29}}</ref> and add the [[JavaScript syntax#Declaration and assignment|assignment declaration]]. Add the value to declare the constant. Note that constants cannot be changed afterward, which should be self-explanatory. Normal variables work the same way, and can be changed accordingly depending on user input. Variables can also hold strings,<ref>{{Citation |title=String (computer science) |date=2022-08-01 |url=https://en.wikipedia.org/w/index.php?title=String_(computer_science)&oldid=1101756832 |work=Wikipedia |language=en |access-date=2022-08-29}}</ref> which are useful for input such as authorization<ref>{{Citation |title=Authorization |date=2022-08-18 |url=https://en.wikipedia.org/w/index.php?title=Authorization&oldid=1105166484 |work=Wikipedia |language=en |access-date=2022-08-29}}</ref> or for a search engine.<ref>{{Citation |title=Search engine |date=2022-08-28 |url=https://en.wikipedia.org/w/index.php?title=Search_engine&oldid=1107150189 |work=Wikipedia |language=en |access-date=2022-08-29}}</ref> Variables can also be undefined<ref>{{Citation |title=Undefined value |date=2021-12-09 |url=https://en.wikipedia.org/w/index.php?title=Undefined_value&oldid=1059485044 |work=Wikipedia |language=en |access-date=2022-08-29}}</ref> or null.<ref>{{Citation |title=Null character |date=2022-08-10 |url=https://en.wikipedia.org/w/index.php?title=Null_character&oldid=1103680343 |work=Wikipedia |language=en |access-date=2022-08-29}}</ref>


=== Functions ===
=== Functions ===
Functions<ref>{{Citation |title=Function object |date=2022-04-22 |url=https://en.wikipedia.org/w/index.php?title=Function_object&oldid=1084126278 |work=Wikipedia |language=en |access-date=2022-08-29}}</ref> are a keyword used in [[object-oriented programming]]. These are used to run code multiple times, for example, a login button. They can setup the procedure and insert it inside of a function named ''loginProcedure''. Using the [[Document Object Model]], they can have the function execute when an [[HTML element]] is clicked.
Functions<ref>{{Citation |title=Function object |date=2022-04-22 |url=https://en.wikipedia.org/w/index.php?title=Function_object&oldid=1084126278 |work=Wikipedia |language=en |access-date=2022-08-29}}</ref> are keywords used in [[object-oriented programming]]. These are used to run code multiple times, for example, for a login button. They can set up the procedure and insert it inside a function named ''loginProcedure''. Using the [[Document Object Model]], they can have the function execute when an [[HTML element]] is clicked.


=== Event Keywords ===
=== Event Keywords ===
[[Event (computing)|Events]] is a trigger usually initiated by user input,<ref name=":0" /> which allows certain blocks of code to execute. Here's a [[HTML attribute#Event attributes|complete list]].
[[Event (computing)|Events]] are triggers usually initiated by user input,<ref name=":0" /> which allow certain blocks of code to execute. Here's a [[HTML attribute#Event attributes|complete list]].


=== WebSockets and User Connections ===
=== WebSockets and User Connections ===
User connections include social networking,<ref>{{Citation |title=Social networking service |date=2022-08-22 |url=https://en.wikipedia.org/w/index.php?title=Social_networking_service&oldid=1105837230 |work=Wikipedia |language=en |access-date=2022-08-29}}</ref> messaging between users,<ref>{{Citation |title=Message |date=2022-07-26 |url=https://en.wikipedia.org/w/index.php?title=Message&oldid=1100585875 |work=Wikipedia |language=en |access-date=2022-08-29}}</ref> or playing an online game.<ref>{{Citation |title=Multiplayer video game |date=2022-08-12 |url=https://en.wikipedia.org/w/index.php?title=Multiplayer_video_game&oldid=1104068378 |work=Wikipedia |language=en |access-date=2022-08-29}}</ref> WebSocket<ref>{{Citation |title=WebSocket |date=2022-08-06 |url=https://en.wikipedia.org/w/index.php?title=WebSocket&oldid=1102718692 |work=Wikipedia |language=en |access-date=2022-08-29}}</ref> is a protocol used for seamless and fast communication listening on a port.<ref>{{Citation |title=Port (computer networking) |date=2022-08-04 |url=https://en.wikipedia.org/w/index.php?title=Port_(computer_networking)&oldid=1102379124 |work=Wikipedia |language=en |access-date=2022-08-29}}</ref> Encoded messages are sent over this line, usually in a JSON format.<ref>{{Citation |title=JSON |date=2022-08-25 |url=https://en.wikipedia.org/w/index.php?title=JSON&oldid=1106610160 |work=Wikipedia |language=en |access-date=2022-08-29}}</ref> WebSocket is supported by [[Google Chrome]], [[Firefox]], [[Safari (web browser)|Safari]], [[Microsoft Edge]], [[Internet Explorer]], and [[Opera (web browser)|Opera]]. This server can be utilized with a variable. Declare a variable and set the value to "new WebSocket()". Inside of the parentheses put the [[URL|URL (Uniform Resource Locator)]] of your WebSocket connection. Create custom functions for this to create a [[Instant messaging|chat application]] or another idea.
User connections include social networking,<ref>{{Citation |title=Social networking service |date=2022-08-22 |url=https://en.wikipedia.org/w/index.php?title=Social_networking_service&oldid=1105837230 |work=Wikipedia |language=en |access-date=2022-08-29}}</ref> messaging between users,<ref>{{Citation |title=Message |date=2022-07-26 |url=https://en.wikipedia.org/w/index.php?title=Message&oldid=1100585875 |work=Wikipedia |language=en |access-date=2022-08-29}}</ref> or playing an online game.<ref>{{Citation |title=Multiplayer video game |date=2022-08-12 |url=https://en.wikipedia.org/w/index.php?title=Multiplayer_video_game&oldid=1104068378 |work=Wikipedia |language=en |access-date=2022-08-29}}</ref> WebSocket<ref>{{Citation |title=WebSocket |date=2022-08-06 |url=https://en.wikipedia.org/w/index.php?title=WebSocket&oldid=1102718692 |work=Wikipedia |language=en |access-date=2022-08-29}}</ref> is a protocol used for seamless and fast communication listening on a port.<ref>{{Citation |title=Port (computer networking) |date=2022-08-04 |url=https://en.wikipedia.org/w/index.php?title=Port_(computer_networking)&oldid=1102379124 |work=Wikipedia |language=en |access-date=2022-08-29}}</ref> Encoded messages are sent over this line, usually in a JSON format.<ref>{{Citation |title=JSON |date=2022-08-25 |url=https://en.wikipedia.org/w/index.php?title=JSON&oldid=1106610160 |work=Wikipedia |language=en |access-date=2022-08-29}}</ref> WebSocket is supported by [[Google Chrome]], [[Firefox]], [[Safari (web browser)|Safari]], [[Microsoft Edge]], [[Internet Explorer]], and [[Opera (web browser)|Opera]]. This server can be utilized with a variable. Declare a variable and set the value to "new WebSocket()". Inside the parentheses put the [[URL|URL (Uniform Resource Locator)]] of your WebSocket connection. Create custom functions to create a [[Instant messaging|chat application]] or another idea.


=== Recap ===
=== Recap ===
View the references for more info on this topic. Event keywords, WebSockets, Functions, and Variables were all listed in this page.<syntaxhighlight lang="javascript" line="1">
View the references for more info on this topic. Event keywords, WebSockets, Functions, and Variables were all listed on this page.<syntaxhighlight lang="javascript" line="1">
// Variables
// Variables
var variable = 1;
var variable = 1;

Latest revision as of 14:35, 27 August 2026



JavaScript Basics

Variables

Variables[1] are data stored as values in a named space. Variables can be used as mathematical constants,[2] used in math commands to generate user output,[3] such as e,[4] which has a value of 2.718281828459045. To declare a new constant, type the keyword "const",[5] and add the assignment declaration. Add the value to declare the constant. Note that constants cannot be changed afterward, which should be self-explanatory. Normal variables work the same way, and can be changed accordingly depending on user input. Variables can also hold strings,[6] which are useful for input such as authorization[7] or for a search engine.[8] Variables can also be undefined[9] or null.[10]

Functions

Functions[11] are keywords used in object-oriented programming. These are used to run code multiple times, for example, for a login button. They can set up the procedure and insert it inside a function named loginProcedure. Using the Document Object Model, they can have the function execute when an HTML element is clicked.

Event Keywords

Events are triggers usually initiated by user input,[3] which allow certain blocks of code to execute. Here's a complete list.

WebSockets and User Connections

User connections include social networking,[12] messaging between users,[13] or playing an online game.[14] WebSocket[15] is a protocol used for seamless and fast communication listening on a port.[16] Encoded messages are sent over this line, usually in a JSON format.[17] WebSocket is supported by Google Chrome, Firefox, Safari, Microsoft Edge, Internet Explorer, and Opera. This server can be utilized with a variable. Declare a variable and set the value to "new WebSocket()". Inside the parentheses put the URL (Uniform Resource Locator) of your WebSocket connection. Create custom functions to create a chat application or another idea.

Recap

View the references for more info on this topic. Event keywords, WebSockets, Functions, and Variables were all listed on this page.

// Variables
var variable = 1;
const constant = 2;
// Better to use let keyword
let username = user;

// Functions
function myFunction() {
    console.log("Hello World!")
}
// Execute this function
myFunction()

// WebSockets
let socket = new WebSocket("server-url")
/* Add your custom WebSocket
functionality here! */
View the references for more info.

References

  1. ↑ "Variable (computer science)", Wikipedia, 2022-08-19, retrieved 2022-08-29
  2. ↑ "Constant (mathematics)", Wikipedia, 2022-06-02, retrieved 2022-08-29
  3. ↑ 3.0 3.1 "Input/output", Wikipedia, 2022-08-28, retrieved 2022-08-29
  4. ↑ "e (mathematical constant)", Wikipedia, 2022-08-26, retrieved 2022-08-29
  5. ↑ "const (computer programming)", Wikipedia, 2022-08-20, retrieved 2022-08-29
  6. ↑ "String (computer science)", Wikipedia, 2022-08-01, retrieved 2022-08-29
  7. ↑ "Authorization", Wikipedia, 2022-08-18, retrieved 2022-08-29
  8. ↑ "Search engine", Wikipedia, 2022-08-28, retrieved 2022-08-29
  9. ↑ "Undefined value", Wikipedia, 2021-12-09, retrieved 2022-08-29
  10. ↑ "Null character", Wikipedia, 2022-08-10, retrieved 2022-08-29
  11. ↑ "Function object", Wikipedia, 2022-04-22, retrieved 2022-08-29
  12. ↑ "Social networking service", Wikipedia, 2022-08-22, retrieved 2022-08-29
  13. ↑ "Message", Wikipedia, 2022-07-26, retrieved 2022-08-29
  14. ↑ "Multiplayer video game", Wikipedia, 2022-08-12, retrieved 2022-08-29
  15. ↑ "WebSocket", Wikipedia, 2022-08-06, retrieved 2022-08-29
  16. ↑ "Port (computer networking)", Wikipedia, 2022-08-04, retrieved 2022-08-29
  17. ↑ "JSON", Wikipedia, 2022-08-25, retrieved 2022-08-29


This article "JavaScript Basics" is from Wikipedia. The list of its authors can be seen in its historical and/or the page Edithistory:JavaScript Basics. Articles copied from Draft Namespace on Wikipedia could be seen on the Draft Namespace of Wikipedia and not main one.