Adam.M
Adam.M

Reputation: 189

How to create a global variable in jQuery

I am a student and I am currently learning jQuery.

Create a toDos global variable holding three to do items, wake up, eat breakfast, and code.

I figured I need to make a global variable of type array which holds the three items, but I have no idea how to write this in jQuery, any tips ?

Upvotes: 0

Views: 1412

Answers (3)

Thomson Mixab
Thomson Mixab

Reputation: 657

jQuery library is build from JavaScript. Here is how to create global variable in JavaScript.

var data = ["wake up","eat breakfast","code"];

alert(data[0]);  // will display "wake up"

Upvotes: 0

Prakash S
Prakash S

Reputation: 2063

You can use 'window.toDos' jquery as such does not have globals. It is just a library. only the window which hoists the execution context has globals

Read more here. https://developer.mozilla.org/en-US/docs/Glossary/Global_object

Upvotes: 0

F.E
F.E

Reputation: 838

You can do something like this.

window.doDos = Jquery.doDos = {
   wakeUp: 'value',
   breakfast: 'value',
   items: [some array here],
}

Upvotes: 1

Related Questions