4.7 KiB
jsPsych is a JavaScript library for creating behavioral experiments that run in a web browser. jsPsych creates a framework for defining experiments and provides a set of flexible plugins that create different kinds of tasks a subject could complete during an experiment. By assembling different plugins together and customizing the parameters of each, it is possible to create many different types of experiments.
Here is a simple example of how to use the instructions plugin:

var trial = {
type: 'instructions',
pages: [
'Welcome to the experiment. Click next to begin.',
'<div>In this experiment, you will view a ' +
'series of images and answer questions.<br>' +
'Answer with the keys "y" or "n".',
'Here is an example:<br><br> ' +
'<img src="img/age/of2.jpg"></img><br><br>' +
'Is this person OLD or YOUNG?'
],
show_clickable_nav: true
}
jsPsych.init({
timeline: [trial],
});
This is an example of the image-keyboard-response plugin:

And for a slightly longer experiment example, here is a flanker experiment which uses the html-keyboard-response plugin:

Documentation
Documentation is available at docs.jspsych.org.
Need help?
For questions about using the library, please post to the jsPsych e-mail list. This creates a public archive of questions and solutions.
Contributing
Contributions to the code are welcome. Please use the Issue tracker system to report bugs or discuss suggestions for new features and improvements. If you would like to contribute code, submit a Pull request.
Citation
If you use this library in academic work, please cite the paper that describes jsPsych:
de Leeuw, J.R. (2015). jsPsych: A JavaScript library for creating behavioral experiments in a Web browser. Behavior Research Methods, 47(1), 1-12. doi:10.3758/s13428-014-0458-y
Response times
Wondering if jsPsych can be used for research that depends on accurate response time measurement? For most purposes, the answer is yes. Response time measurements in jsPsych (and JavaScript in general) are comparable to those taken in standard lab software like Psychophysics Toolbox and E-Prime. Response times measured in JavaScript tend to be a little bit longer (10-40ms), but have similar variance. See the following references for extensive work on this topic.
- de Leeuw, J. R., & Motz, B. A. (2016). Psychophysics in a Web browser? Comparing response times collected with JavaScript and Psychophysics Toolbox in a visual search task. Behavior Research Methods, 48(1), 1-12.
- Hilbig, B. E. (2016). Reaction time effects in lab- versus web-based research: Experimental evidence. Behavior Research Methods, 48(4), 1718-1724.
- Pinet, S., Zielinski, C., Mathôt, S. et al. (in press). Measuring sequences of keystrokes with jsPsych: Reliability of response times and interkeystroke intervals. Behavior Research Methods.
- Reimers, S., & Stewart, N. (2015). Presentation and response time accuracy in Adobe Flash and HTML5/JavaScript Web experiments. Behavior Research Methods, 47(2), 309-327.
Credits
jsPsych was created by Josh de Leeuw (@jodeleeuw).
There have been many contributors to the library. Thank you!